-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPrograms.vue
More file actions
127 lines (126 loc) · 4.28 KB
/
Programs.vue
File metadata and controls
127 lines (126 loc) · 4.28 KB
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
<!--
This file is part of the Meeds project (https://meeds.io/).
Copyright (C) 2022 Meeds Association
contact@meeds.io
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-->
<template>
<v-app class="application-body">
<main>
<gamification-programs-list
v-show="!displayProgramDetail"
id="engagementCenterProgramsTab"
:is-administrator="isAdministrator"
:is-program-manager="isProgramManager"
:can-add-program="canAddProgram"
@administrators-loaded="administrators = $event" />
<gamification-program-detail
v-if="displayProgramDetail"
:program="program"
:administrators="administrators"
:newly-created="newlyCreated"
:is-administrator="isAdministrator"
@updated="program = $event" />
</main>
<engagement-center-rule-extensions />
<gamification-program-drawer
ref="programDrawer"
:is-administrator="isAdministrator" />
</v-app>
</template>
<script>
export default {
props: {
isAdministrator: {
type: Boolean,
default: false,
},
isProgramManager: {
type: Boolean,
default: false,
},
canAddProgram: {
type: Boolean,
default: false,
},
},
data: () => ({
tab: null,
program: null,
administrators: null,
displayProgramDetail: false,
newlyCreated: false,
programsLinkBasePath: `${eXo.env.portal.context}/${eXo.env.portal.engagementSiteName}/contributions/programs`,
}),
watch: {
displayProgramDetail() {
if (this.displayProgramDetail && this.program?.id) {
window.history.pushState('programs', this.$t('engagementCenter.label.programs'), `${this.programsLinkBasePath}/${this.program.id}`);
} else {
window.history.pushState('programs', this.$t('engagementCenter.label.programs'), `${this.programsLinkBasePath}`);
}
},
},
created() {
this.$root.$on('program-added', this.openCreatedProgramDetail);
this.$root.$on('rule-created', this.resetNewlyCreated);
this.$root.$on('rule-updated', this.updateOpenedProgram);
this.$root.$on('rule-deleted', this.updateOpenedProgram);
this.$root.$on('open-program-detail', this.openProgramDetail);
this.$root.$on('open-program-detail-by-id', this.openProgramDetailById);
this.$root.$on('close-program-detail', () => this.displayProgramDetail = false);
this.init();
},
methods: {
init() {
const urlPath = document.location.pathname;
const id = urlPath.match( /\d+/ ) && urlPath.match( /\d+/ ).join('');
if (id) {
this.openProgramDetailById(id);
}
},
resetNewlyCreated() {
this.newlyCreated = false;
this.updateOpenedProgram();
},
updateOpenedProgram() {
if (this.displayProgramDetail && this.program?.id) {
this.openProgramDetailById(this.program.id);
}
},
openProgramDetailById(id, newlyCreated) {
this.$programService.getProgramById(id, {
lang: eXo.env.portal.language,
expand: 'countActiveRulesWhenDisabled',
})
.then(program => {
if (program?.id) {
this.administrators = program.administrators;
this.openProgramDetail(program, null, newlyCreated);
}
});
},
openCreatedProgramDetail(program) {
this.openProgramDetail(program, null, true);
},
openProgramDetail(program, administrators, newlyCreated) {
this.newlyCreated = newlyCreated || false;
if (!this.administrators) {
this.administrators = program.administrators || administrators;
}
this.program = JSON.parse(JSON.stringify(program));
this.displayProgramDetail = true;
},
}
};
</script>