Skip to content

Commit 84e7d7a

Browse files
committed
Allow only one set of change categories for all library codes
1 parent fd41d23 commit 84e7d7a

File tree

4 files changed

+103
-43
lines changed

4 files changed

+103
-43
lines changed

vue-client/src/components/usersettings/change-categories.vue

+56-28
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,99 @@ export default {
88
mixins: [LensMixin],
99
data() {
1010
return {
11-
expanded: false,
11+
categoriesIsExpanded: false,
12+
sigelIsExpanded: false,
1213
};
1314
},
1415
props: {
1516
sigel: Object,
1617
availableCategories: [],
18+
availableSigels: [],
1719
},
1820
methods: {
19-
updateChangeCategories(e, sigel, categoryId) {
20-
this.$store.dispatch('updateSubscribedChangeCategories', { libraryId: this.sigelUri, categoryId: categoryId, checked: e.target.checked });
21+
updateSigel(e, sigel) {
22+
console.log('available sigels', JSON.stringify(this.availableSigels));
23+
console.log('sigelCode', sigel);
24+
this.$store.dispatch('updateSubscribedSigel', { libraryId: this.sigelUri(sigel), checked: e.target.checked });
2125
},
22-
toggleExpanded() {
23-
this.expanded = !this.expanded;
26+
updateCategory(e, categoryId) {
27+
this.$store.dispatch('updateSubscribedChangeCategory', { categoryId: categoryId, checked: e.target.checked });
28+
},
29+
toggleSigelExpanded() {
30+
this.sigelIsExpanded = !this.sigelIsExpanded;
31+
},
32+
toggleCategoriesExpanded() {
33+
this.categoriesIsExpanded = !this.categoriesIsExpanded;
2434
},
2535
isActiveCategory(categoryId) {
26-
const obj = this.userChangeCategories.find(c => c.heldBy === this.sigelUri);
36+
const obj = this.userChangeCategories[0];
2737
return obj ? obj.triggers.includes(categoryId) : false;
2838
},
39+
isActiveSigel(sigel) {
40+
console.log('this.userChangeCategories', JSON.stringify(this.userChangeCategories));
41+
const obj = this.userChangeCategories.find(c => c.heldBy === this.sigelUri(sigel));
42+
return !!obj;
43+
},
2944
label(obj) {
3045
return this.getLabel(obj);
3146
},
47+
sigelLabel(sigel) {
48+
return StringUtil.getSigelLabel(sigel);
49+
},
50+
sigelUri(sigel) {
51+
return StringUtil.getLibraryUri(sigel.code);
52+
},
3253
},
3354
computed: {
3455
...mapGetters([
3556
'userChangeCategories',
3657
]),
37-
isExpanded() {
38-
return this.expanded;
39-
},
40-
sigelLabel() {
41-
return StringUtil.getSigelLabel(this.sigel);
42-
},
43-
sigelUri() {
44-
return StringUtil.getLibraryUri(this.sigel.code);
45-
},
4658
},
4759
mounted() {
48-
this.$nextTick(() => {
49-
});
5060
},
5161
};
5262
</script>
5363

54-
<template>
64+
<template><div>
5565
<div class="Categories">
56-
<div class="Categories-label" @click="toggleExpanded">
57-
<i class="Categories-arrow fa fa-chevron-right"
58-
:class="{'icon is-expanded' : isExpanded}"
59-
></i>
60-
{{ sigelLabel }}
66+
<div class="Categories-label" @click="toggleSigelExpanded">
67+
<i class="Categories-arrow fa fa-chevron-right"
68+
:class="{'icon is-expanded' : sigelIsExpanded}"
69+
></i>
70+
{{ 'Collections' | translatePhrase }}
71+
</div>
72+
<div v-if="sigelIsExpanded">
73+
<div class="Categories-row" v-for="sigel in availableSigels" :key="sigel.code">
74+
<div class="Categories-key">{{ sigelLabel(sigel) }}</div>
75+
<div class="Categories-value">
76+
<input id="categoryCheckbox"
77+
class="customCheckbox-input"
78+
type="checkbox"
79+
@change="e => updateSigel(e, sigel)" :checked="isActiveSigel(sigel)">
80+
<div class="customCheckbox-icon"></div>
81+
</div>
6182
</div>
62-
63-
<div v-if="isExpanded">
83+
</div>
84+
<div class="Categories-label" @click="toggleCategoriesExpanded">
85+
<i class="Categories-arrow fa fa-chevron-right"
86+
:class="{'icon is-expanded' : categoriesIsExpanded}"
87+
></i>
88+
{{ 'Change categories' | translatePhrase }}
89+
</div>
90+
<div v-if="categoriesIsExpanded">
6491
<div class="Categories-row" v-for="category in availableCategories" :key="category['@id']">
6592
<div class="Categories-key">{{ label(category) }}</div>
6693
<div class="Categories-value">
6794
<input id="categoryCheckbox"
6895
class="customCheckbox-input"
6996
type="checkbox"
70-
@change="updateChangeCategories(...arguments, sigel, category['@id'])" :checked="isActiveCategory(category['@id'])">
97+
@change="e => updateCategory(e, category['@id'])" :checked="isActiveCategory(category['@id'])">
7198
<div class="customCheckbox-icon"></div>
7299
</div>
73100
</div>
74101
</div>
75102
</div>
103+
</div>
76104
</template>
77105

78106
<style scoped lang="less">
@@ -96,11 +124,11 @@ export default {
96124
border-width: 0px 0px 1px 0px;
97125
}
98126
&-key {
99-
padding: 0.5em;
127+
padding: 0.6em;
100128
width: 50%;
101129
}
102130
&-value {
103-
padding: 0.5em;
131+
padding: 0.6em;
104132
width: 50%;
105133
}
106134
&-label {

vue-client/src/components/usersettings/user-settings.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ export default {
187187
</table>
188188
<h5 class="uppercaseHeading--bold">{{ 'Subscribe to change notes' | translatePhrase }}</h5>
189189
<div class="UserSettings-changeCategories">
190-
<div v-for="sigel in sortedSigels" :key="sigel.code">
191-
<change-categories :sigel="sigel" :userChangeCategories="userChangeCategories" :availableCategories="availableChangeCategories"/>
192-
</div>
190+
<change-categories :available-sigels="sortedSigels" :userChangeCategories="userChangeCategories" :availableCategories="availableChangeCategories"/>
193191
</div>
194192
</form>
195193
<button class="btn btn-primary btn--lg UserSettings-logout" @click="logout">{{"Log out" | translatePhrase}}</button>

vue-client/src/resources/json/i18n.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@
408408
"Unlinked entity": "Olänkad entitet",
409409
"Subscribe to change notes": "Prenumerera på ändringsmeddelanden",
410410
"Changes": "Ändringar",
411-
"Handled": "Hanterad"
411+
"Handled": "Hanterad",
412+
"Change categories": "Ändringskategorier",
413+
"Collections": "Sigler"
412414
}
413415
}

vue-client/src/store.js

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue';
22
import Vuex from 'vuex';
3-
import { cloneDeep, each, set, get, assign, filter, isObject } from 'lodash-es';
3+
import { cloneDeep, each, set, get, assign, filter, isObject, isEmpty } from 'lodash-es';
44
import ClientOAuth2 from 'client-oauth2';
55
import * as VocabUtil from 'lxljs/vocab';
66
import * as StringUtil from 'lxljs/string';
@@ -530,19 +530,51 @@ const store = new Vuex.Store({
530530
dispatch('modifyUserDatabase', { property: 'notificationEmail', value: userEmail });
531531
}
532532
},
533+
updateSubscribedSigel({ dispatch, state }, { libraryId, checked }) {
534+
let notifications = cloneDeep(state.userDatabase.requestedNotifications) || [];
535+
const notification = notifications[0];
536+
let categories = [];
537+
if (notification) {
538+
categories = notification.triggers;
539+
}
540+
if (checked) {
541+
console.log('changed, pushing notication', { heldBy: libraryId, triggers: categories });
542+
notifications.push({ heldBy: libraryId, triggers: categories });
543+
} else if (notifications.length === 1) { // Unchecked & removing the last element
544+
notifications.forEach((n) => { n.heldBy = 'none'; });
545+
} else { // Unchecked => remove whole notification
546+
notifications = notifications.filter(n => n.heldBy !== libraryId);
547+
}
548+
549+
dispatch('modifyUserDatabase', { property: 'requestedNotifications', value: notifications });
550+
},
551+
updateSubscribedChangeCategory({ dispatch, state }, { categoryId, checked }) {
552+
const notifications = cloneDeep(state.userDatabase.requestedNotifications) || [];
553+
if (isEmpty(notifications)) {
554+
notifications.push({ heldBy: 'none', triggers: [categoryId] });
555+
}
556+
notifications.forEach((n) => {
557+
if (checked) {
558+
n.triggers.push(categoryId);
559+
} else { // Unchecked => remove from triggers
560+
n.triggers = n.triggers.filter(id => id !== categoryId);
561+
}
562+
});
563+
dispatch('modifyUserDatabase', { property: 'requestedNotifications', value: notifications });
564+
},
533565
updateSubscribedChangeCategories({ dispatch, state }, { libraryId, categoryId, checked }) {
534566
const notifications = cloneDeep(state.userDatabase.requestedNotifications) || [];
535-
536-
const notification = notifications?.find(obj => obj.heldBy === libraryId);
537-
if (checked) {
538-
if (notification) {
539-
notification.triggers.push(categoryId);
540-
} else {
541-
notifications.push({ heldBy: libraryId, triggers: [categoryId] });
567+
notifications?.forEach((n) => {
568+
if (checked) {
569+
if (n) {
570+
n.triggers.push(categoryId);
571+
} else {
572+
n.push({ heldBy: libraryId, triggers: [categoryId] });
573+
}
574+
} else { // Unchecked => remove from triggers
575+
n.triggers = n.triggers.filter(id => id !== categoryId);
542576
}
543-
} else { // Unchecked => remove from triggers
544-
notification.triggers = notification.triggers.filter(id => id !== categoryId);
545-
}
577+
});
546578
dispatch('modifyUserDatabase', { property: 'requestedNotifications', value: notifications });
547579
},
548580
purgeChangeCategories({ dispatch }) {

0 commit comments

Comments
 (0)