summaryrefslogtreecommitdiffstats
path: root/settings/src/components/appList/appItem.vue
blob: 72cf8b4e3ee51fb0a925db414dec337d6da8d6dd (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
<!--
  - @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  -
  - @author Julius Härtl <jus@bitgrid.net>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->

<template>
	<div class="section" v-bind:class="{ selected: isSelected }">
		<div class="app-image app-image-icon" v-on:click="showAppDetails">
			<div v-if="!app.preview" class="icon-settings-dark"></div>
			<img v-if="!app.previewAsIcon && app.preview && listView" :src="app.preview"  width="100%" />

			<svg v-if="listView && app.previewAsIcon && app.preview" width="32" height="32" viewBox="0 0 32 32">
				<defs><filter :id="filterId"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
				<image x="0" y="0" width="32" height="32" preserveAspectRatio="xMinYMin meet" :filter="filterUrl" :xlink:href="app.preview" class="app-icon"></image>
			</svg>

			<img v-if="!listView && app.screenshot" :src="app.screenshot"  width="100%" />
		</div>
		<div class="app-name" v-on:click="showAppDetails">
			{{ app.name }}
		</div>
		<div class="app-summary" v-if="!listView">{{ app.summary }}</div>
		<div class="app-version" v-if="listView">{{ app.version }}</div>

		<div class="app-level">
			<span class="official icon-checkmark" v-if="app.level === 200"
				  v-tooltip.auto="t('settings', 'Official apps are developed by and within the community. They offer central functionality and are ready for production use.')">
				{{ t('settings', 'Official') }}</span>
			<app-score v-if="!listView" :score="app.score"></app-score>
			<a :href="appstoreUrl" v-if="!app.internal && listView">Im Store anzeigen ↗</a>
		</div>


		<div class="app-groups" v-if="listView">
			<div class="groups-enable" v-if="app.active && canLimitToGroups(app)">
				<input type="checkbox" :value="app.id" v-model="groupCheckedAppsData" v-on:change="setGroupLimit" class="groups-enable__checkbox checkbox" :id="prefix('groups_enable', app.id)">
				<label :for="prefix('groups_enable', app.id)">Auf Gruppen beschränken</label>
				<input type="hidden" class="group_select" title="Alle" value="">
				<multiselect v-if="isLimitedToGroups(app)" :options="groups" :value="appGroups" @select="addGroupLimitation" @remove="removeGroupLimitation"
							 :placeholder="t('settings', 'Limit app usage to groups')"
							 label="name" track-by="id" class="multiselect-vue"
							 :multiple="true" :close-on-select="false">
					<span slot="noResult">{{t('settings', 'No results')}}</span>
				</multiselect>
			</div>
		</div>

		<div class="actions">
			<div class="warning" v-if="app.error">{{ app.error }}</div>
			<div class="icon icon-loading-small" v-if="loading(app.id)"></div>
			<input v-if="app.update" class="update" type="button" :value="t('settings', 'Update to {update}', {update:app.update})" v-on:click="update(app.id)" :disabled="installing || loading(app.id)" />
			<input v-if="app.canUnInstall" class="uninstall" type="button" :value="t('settings', 'Remove')" v-on:click="remove(app.id)" :disabled="installing || loading(app.id)" />
			<input v-if="app.active" class="enable" type="button" :value="t('settings','Disable')" v-on:click="disable(app.id)" :disabled="installing || loading(app.id)" />
			<input v-if="!app.active" class="enable" type="button" :value="enableButtonText" v-on:click="enable(app.id)" v-tooltip.auto="enableButtonTooltip" :disabled="!app.canInstall || installing || loading(app.id)" />
		</div>
	</div>
</template>

<script>
	import Multiselect from 'vue-multiselect';
	import AppScore from './appScore';
	import AppManagement from '../appManagement';

	export default {
		name: 'appItem',
		mixins: [AppManagement],
		props: {
			app: {},
			category: {},
			listView: {
				type: Boolean,
				default: true,
			}
		},
		watch: {
			'$route.params.id': function (id) {
				this.isSelected = (this.app.id === id);
			}
		},
		components: {
			Multiselect,
			AppScore,
		},
		data() {
			return {
				isSelected: false,
				groupCheckedAppsData: false,
				scrolled: false,
				filterId: '',
			};
		},
		mounted() {
			if (this.app.groups.length > 0) {
				this.groupCheckedAppsData = true;
			}
			this.isSelected = (this.app.id === this.$route.params.id);
			this.filterId = 'invertIconApps' + Math.floor((Math.random() * 100 )) + new Date().getSeconds() + new Date().getMilliseconds();
		},
		computed: {
			loading() {
				let self = this;
				return function(id) {
					return self.$store.getters.loading(id);
				}
			},
			installing() {
				return this.$store.getters.loading('install');
			},
			filterUrl() {
				return `url(#${this.filterId})`;
			},
			appstoreUrl() {
				return `https://apps.nextcloud.com/apps/${this.app.id}`;
			},
			appGroups() {
				return this.app.groups.map(group => {return {id: group, name: group}});
			},
			groups() {
				return this.$store.getters.getGroups
					.filter(group => group.id !== 'disabled')
					.sort((a, b) => a.name.localeCompare(b.name));
			},
			enableButtonText() {
				if (this.app.needsDownload) {
					return t('settings','Download and enable');
				}
				return t('settings','Enable');
			},
			enableButtonTooltip() {
				if (this.app.needsDownload) {
					return t('settings','The app will be downloaded from the app store');
				}
				return false;
			}
		},
		watchers: {

		},
		methods: {
			showAppDetails() {
				this.$router.push({
					name: 'apps-details',
					params: {category: this.category, id: this.app.id}
				});
			},
			prefix(prefix, content) {
				return prefix + '_' + content;
			},
		}
	}
</script>