summaryrefslogtreecommitdiffstats
path: root/src/components/AddFeed.vue
blob: 7ab4215542c9316af1d2d11a66176dee1c53dbb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
	<NcModal @close="$emit('close')">
		<div id="new-feed" news-add-feed="Navigation.feed">
			<form ng-submit="Navigation.createFeed(Navigation.feed)"
				ng-init="Navigation.feed.autoDiscover=true"
				name="feedform">
				<fieldset ng-disabled="Navigation.addingFeed" style="padding: 16px">
					<input type="text"
						:value="feed"
						ng-model="Navigation.feed.url"
						ng-class="{'ng-invalid':
                        !Navigation.addingFeed &&
                        Navigation.feedUrlExists(Navigation.feed.url)
                    }"
						:placeholder="t('news', 'Web address')"
						name="address"
						pattern="[^\s]+"
						required
						autofocus>

					<p class="error"
						ng-show="!Navigation.addingFeed &&
                        Navigation.feedUrlExists(Navigation.feed.url)">
						{{ t("news", "Feed exists already!") }}
					</p>

					<!-- select a folder -->
					<CheckboxRadioSwitch :checked.sync="createNewFolder" type="switch">
						{{ t("news", "New folder") }}?
					</CheckboxRadioSwitch>

					<NcMultiselect v-if="!createNewFolder"
						v-model="folder"
						:options="folders"
						track-by="id"
						label="name" />

					<!-- add a folder -->
					<input v-if="createNewFolder"
						type="text"
						ng-model="Navigation.feed.newFolder"
						ng-class="{'ng-invalid':
                            !Navigation.addingFeed &&
                            !Navigation.addingFeed &&
                            Navigation.showNewFolder &&
                            Navigation.folderNameExists(
                                Navigation.feed.newFolder
                            )
                        }"
						:placeholder="t('news', 'Folder name')"
						name="folderName"
						style="width: 90%"
						required>

					<p class="error"
						ng-show="!Navigation.addingFeed &&
                    Navigation.folderNameExists(Navigation.feed.newFolder)">
						{{ t("news", "Folder exists already!") }}
					</p>

					<!-- basic auth -->

					<CheckboxRadioSwitch :checked.sync="withBasicAuth" type="switch">
						{{ t("news", "Credentials") }}?
					</CheckboxRadioSwitch>

					<div v-if="withBasicAuth" class="add-feed-basicauth">
						<p class="warning">
							{{
								t(
									"news",
									"HTTP Basic Auth credentials must be stored unencrypted! Everyone with access to the server or database will be able to access them!"
								)
							}}>
						</p>
						<input type="text"
							ng-model="Navigation.feed.user"
							:placeholder="t('news', 'Username')"
							name="user"
							autofocus>

						<input type="password"
							ng-model="Navigation.feed.password"
							:placeholder="t('news', 'Password')"
							name="password"
							autocomplete="new-password">
					</div>

					<NcCheckboxRadioSwitch :checked.sync="autoDiscover" type="switch">
						{{ t("news", "Auto discover Feed") }}?
					</NcCheckboxRadioSwitch>

					<NcButton :wide="true"
						type="primary"
						ng-disabled="
                        Navigation.feedUrlExists(Navigation.feed.url) ||
                                (
                                    Navigation.showNewFolder &&
                                    Navigation.folderNameExists(folder.name)
                                )"
						@click="addFeed()">
						{{ t("news", "Subscribe") }}
					</NcButton>
				</fieldset>
			</form>
		</div>
	</NcModal>
</template>

<script>
/* eslint-disable vue/require-prop-type-constructor */

import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcMultiselect from '@nextcloud/vue/dist/Components/NcMultiselect.js'

export default {
	name: 'AddFeed',
	components: {
		NcModal,
		NcCheckboxRadioSwitch,
		NcButton,
		NcMultiselect,
	},
	props: {
		feed: '',
	},
	emits: ['close'],
	data() {
		return {
			folder: {},
			autoDiscover: true,
			createNewFolder: false,
			withBasicAuth: false,
		}
	},
	computed: {
		folders() {
			return this.$store.state.folders
		},
	},
	methods: {
		newFolder() {
			this.createNewFolder = true
		},
		abortNewFolder() {
			this.createNewFolder = false
		},
		addFeed() {
			this.$store.dispatch('addFeed', {
				feedReq: {
					url: this.feed,
					folder: this.folder,
					autoDiscover: true,
				},
			})
		},
	},
}
</script>

<style scoped>
input {
    width: 100%
}

.multiselect {
    width: 100%
}
</style>