lesli_calendar 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +5 -0
- data/app/assets/config/lesli_calendar_manifest.js +40 -0
- data/app/assets/images/lesli_calendar/calendar-logo.svg +101 -0
- data/app/assets/javascripts/lesli_calendar/application.js +4658 -0
- data/app/assets/stylesheets/lesli_calendar/application.css +604 -0
- data/app/controllers/lesli_calendar/application_controller.rb +4 -0
- data/app/controllers/lesli_calendar/calendars_controller.rb +71 -0
- data/app/controllers/lesli_calendar/dashboards_controller.rb +60 -0
- data/app/controllers/lesli_calendar/events_controller.rb +60 -0
- data/app/helpers/lesli_calendar/application_helper.rb +4 -0
- data/app/helpers/lesli_calendar/calendars_helper.rb +4 -0
- data/app/helpers/lesli_calendar/dashboards_helper.rb +4 -0
- data/app/helpers/lesli_calendar/events_helper.rb +4 -0
- data/app/jobs/lesli_calendar/application_job.rb +4 -0
- data/app/mailers/lesli_calendar/application_mailer.rb +6 -0
- data/app/models/lesli_calendar/account.rb +45 -0
- data/app/models/lesli_calendar/application_record.rb +5 -0
- data/app/models/lesli_calendar/calendar.rb +5 -0
- data/app/models/lesli_calendar/dashboard.rb +4 -0
- data/app/models/lesli_calendar/event.rb +4 -0
- data/app/services/lesli_calendar/calendar_service.rb +56 -0
- data/app/views/lesli_calendar/calendars/_calendar.html.erb +2 -0
- data/app/views/lesli_calendar/calendars/_form.html.erb +17 -0
- data/app/views/lesli_calendar/calendars/edit.html.erb +10 -0
- data/app/views/lesli_calendar/calendars/index.html.erb +14 -0
- data/app/views/lesli_calendar/calendars/new.html.erb +9 -0
- data/app/views/lesli_calendar/calendars/show.html.erb +1 -0
- data/app/views/lesli_calendar/dashboards/_dashboard.html.erb +2 -0
- data/app/views/lesli_calendar/dashboards/_form.html.erb +17 -0
- data/app/views/lesli_calendar/dashboards/edit.html.erb +10 -0
- data/app/views/lesli_calendar/dashboards/index.html.erb +14 -0
- data/app/views/lesli_calendar/dashboards/new.html.erb +9 -0
- data/app/views/lesli_calendar/dashboards/show.html.erb +1 -0
- data/app/views/lesli_calendar/events/_event.html.erb +2 -0
- data/app/views/lesli_calendar/events/_form.html.erb +17 -0
- data/app/views/lesli_calendar/events/edit.html.erb +10 -0
- data/app/views/lesli_calendar/events/index.html.erb +1 -0
- data/app/views/lesli_calendar/events/new.html.erb +9 -0
- data/app/views/lesli_calendar/events/show.html.erb +10 -0
- data/app/views/lesli_calendar/partials/_engine-navigation.html.erb +37 -0
- data/config/locales/translations.en.yml +21 -0
- data/config/locales/translations.es.yml +21 -0
- data/config/locales/translations.fr.yml +21 -0
- data/config/locales/translations.it.yml +21 -0
- data/config/locales/translations.pt.yml +21 -0
- data/config/routes.rb +41 -0
- data/db/migrate/v1.0/0301000110_create_lesli_calendar_accounts.rb +40 -0
- data/db/migrate/v1.0/0301100110_create_lesli_calendar_calendars.rb +46 -0
- data/db/migrate/v1.0/0301110110_create_lesli_calendar_events.rb +57 -0
- data/db/seed/development.rb +17 -0
- data/db/seed/production.rb +17 -0
- data/db/seed/test.rb +17 -0
- data/db/seeds.rb +28 -0
- data/db/tables/0301010210_create_lesli_driver_catalog_event_types.rb +14 -0
- data/db/tables/0301110310_create_lesli_driver_event_actions.rb +16 -0
- data/db/tables/0301110410_create_lesli_driver_event_activities.rb +15 -0
- data/db/tables/0301110510_create_lesli_driver_event_discussions.rb +17 -0
- data/db/tables/0301110610_create_lesli_driver_event_files.rb +16 -0
- data/db/tables/0301110710_create_lesli_driver_event_subscribers.rb +16 -0
- data/db/tables/0301111010_create_lesli_driver_event_attendants.rb +13 -0
- data/lib/lesli_calendar/engine.rb +50 -0
- data/lib/lesli_calendar/version.rb +4 -0
- data/lib/lesli_calendar.rb +6 -0
- data/lib/scss/application.scss +34 -0
- data/lib/scss/calendar.scss +181 -0
- data/lib/tasks/lesli_calendar_tasks.rake +4 -0
- data/lib/vue/application.js +59 -0
- data/lib/vue/apps/calendars/show.vue +87 -0
- data/lib/vue/apps/events/index.vue +48 -0
- data/lib/vue/components/agenda.vue +137 -0
- data/lib/vue/components/calendar.vue +137 -0
- data/lib/vue/components/event.vue +47 -0
- data/lib/vue/components/form.vue +143 -0
- data/lib/vue/components/guests.vue +148 -0
- data/lib/vue/stores/calendar.js +215 -0
- data/lib/vue/stores/events.js +53 -0
- data/lib/vue/stores/guests.js +213 -0
- data/lib/vue/stores/translations.json +152 -0
- data/license +674 -0
- data/readme.md +71 -0
- metadata +154 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
<script setup>
|
2
|
+
|
3
|
+
/*
|
4
|
+
Copyright (c) 2023, all rights reserved.
|
5
|
+
|
6
|
+
All the information provided by this platform is protected by international laws related to
|
7
|
+
industrial property, intellectual property, copyright and relative international laws.
|
8
|
+
All intellectual or industrial property rights of the code, texts, trade mark, design,
|
9
|
+
pictures and any other information belongs to the owner of this platform.
|
10
|
+
|
11
|
+
Without the written permission of the owner, any replication, modification,
|
12
|
+
transmission, publication is strictly forbidden.
|
13
|
+
|
14
|
+
For more information read the license file including with this software.
|
15
|
+
|
16
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
17
|
+
*/
|
18
|
+
|
19
|
+
// · Import components, libraries and tools
|
20
|
+
import { onMounted, inject } from "vue"
|
21
|
+
|
22
|
+
// · import lesli stores
|
23
|
+
import { useGuests } from 'LesliCalendar/vue/stores/guests'
|
24
|
+
import { useCalendar } from 'LesliCalendar/vue/stores/calendar'
|
25
|
+
|
26
|
+
// · implement stores
|
27
|
+
const storeGuests = useGuests()
|
28
|
+
const storeCalendar = useCalendar()
|
29
|
+
|
30
|
+
// · initialize/inject plugins
|
31
|
+
const date = inject("date")
|
32
|
+
const today = date.date(new Date())
|
33
|
+
|
34
|
+
onMounted(() => {
|
35
|
+
storeGuests.getAttendants()
|
36
|
+
storeGuests.getUsers()
|
37
|
+
})
|
38
|
+
|
39
|
+
function submitAttendant(user) {
|
40
|
+
user.checked = !user.checked;
|
41
|
+
if (user.checked) storeGuests.postAttendant(user)
|
42
|
+
else storeGuests.deleteInvite(user)
|
43
|
+
}
|
44
|
+
|
45
|
+
function confirmedInvitesCount() {
|
46
|
+
return storeGuests.attendants.filter(attendant => attendant.confirmed_at_string).length
|
47
|
+
}
|
48
|
+
|
49
|
+
function totalInvitesCount() {
|
50
|
+
return storeGuests.attendants.length
|
51
|
+
}
|
52
|
+
|
53
|
+
const translations = {
|
54
|
+
main: I18n.t('driver.events'),
|
55
|
+
core: I18n.t('core.shared'),
|
56
|
+
core_users: I18n.t('core.users'),
|
57
|
+
users: I18n.t('deutscheleibrenten.users'),
|
58
|
+
attendants: I18n.t('driver.event/attendants')
|
59
|
+
}
|
60
|
+
|
61
|
+
const usersTableColumns = [
|
62
|
+
{ field: 'name', label: translations.core.view_text_name },
|
63
|
+
{ field: 'email', label: translations.core.view_text_email }
|
64
|
+
]
|
65
|
+
|
66
|
+
const attendantsTableColumns = [
|
67
|
+
{ field: 'name', label: translations.core.view_text_name },
|
68
|
+
{ field: 'email', label: translations.core.view_text_email }
|
69
|
+
]
|
70
|
+
|
71
|
+
</script>
|
72
|
+
|
73
|
+
<template>
|
74
|
+
<h5 class="title is-5">
|
75
|
+
{{ translations.attendants.view_title_confirmed_invites_count }}: {{ confirmedInvitesCount() }} /
|
76
|
+
{{ translations.attendants.view_title_total_invites_count }}: {{ totalInvitesCount() }}
|
77
|
+
</h5>
|
78
|
+
<lesli-tabs v-model="tab">
|
79
|
+
|
80
|
+
<lesli-tab-item :title="translations.main.view_tab_title_users" icon="person_search">
|
81
|
+
<lesli-toolbar @search="a"></lesli-toolbar>
|
82
|
+
<lesli-table :columns="usersTableColumns" :records="storeGuests.attendant_options.users">
|
83
|
+
<template #buttons="{ record }">
|
84
|
+
<input type="checkbox" v-model="record.checked" @input="submitAttendant(record)"
|
85
|
+
:checked="storeGuests.attendant_options.users.checked">
|
86
|
+
</template>
|
87
|
+
</lesli-table>
|
88
|
+
</lesli-tab-item>
|
89
|
+
|
90
|
+
<lesli-tab-item :title="translations.main.view_tab_title_guests" icon="group_add">
|
91
|
+
<form @submit.prevent="storeGuests.postGuest">
|
92
|
+
<fieldset>
|
93
|
+
<div class="columns">
|
94
|
+
<div class="column">
|
95
|
+
<field label="column_user_main_id">
|
96
|
+
<p>{{ translations.core.view_text_name }}</p>
|
97
|
+
<input class="input is-default" type="text" name="guest_name"
|
98
|
+
v-model="storeGuests.guest.name" />
|
99
|
+
</field>
|
100
|
+
<field label="column_user_main_id">
|
101
|
+
<p>{{ translations.core.view_text_email }}</p>
|
102
|
+
<input class="input is-default" type="email" name="guest_email"
|
103
|
+
v-model="storeGuests.guest.email" />
|
104
|
+
</field>
|
105
|
+
<div class="buttons">
|
106
|
+
<button name="btn-save" type="submit" class="button is-primary is-fullwidth">
|
107
|
+
<span><span class="icon is-small"><i class="fas fa-save"></i></span> </span>
|
108
|
+
</button>
|
109
|
+
</div>
|
110
|
+
</div>
|
111
|
+
</div>
|
112
|
+
</fieldset>
|
113
|
+
</form>
|
114
|
+
</lesli-tab-item>
|
115
|
+
|
116
|
+
<lesli-tab-item :title="translations.main.view_tab_title_attendants_list" icon="groups">
|
117
|
+
<lesli-table :columns="attendantsTableColumns" :records="storeGuests.attendants">
|
118
|
+
<template #buttons="{ record }">
|
119
|
+
|
120
|
+
<button @click="storeGuests.confirmAttendance(record, today)" class="button is-success" :disabled="record.confirmed_at_string">
|
121
|
+
<span v-if="!record.confirmed_at_string && !storeGuests.loading.attendants">
|
122
|
+
{{ translations.main.view_text_click_to_confirm }}
|
123
|
+
</span>
|
124
|
+
<span v-if="storeGuests.loading.attendants">
|
125
|
+
<i class="fas fa-spin fa-circle-notch"></i>
|
126
|
+
</span>
|
127
|
+
<span v-if="record.confirmed_at_string && !storeGuests.loading.attendants">
|
128
|
+
{{ record.confirmed_at_string }}
|
129
|
+
</span>
|
130
|
+
</button>
|
131
|
+
|
132
|
+
<button @click="storeGuests.deleteInvite(record)"
|
133
|
+
class="button is-outlined is-danger">
|
134
|
+
<span v-if="storeGuests.submit.delete">
|
135
|
+
<i class="fas fa-spin fa-circle-notch"></i> {{
|
136
|
+
translations.core.view_btn_deleting
|
137
|
+
}}
|
138
|
+
</span>
|
139
|
+
<span v-else>
|
140
|
+
<i class="fas fa-trash-alt"></i> {{ translations.core.view_btn_delete }}
|
141
|
+
</span>
|
142
|
+
</button>
|
143
|
+
</template>
|
144
|
+
</lesli-table>
|
145
|
+
</lesli-tab-item>
|
146
|
+
|
147
|
+
</lesli-tabs>
|
148
|
+
</template>
|
@@ -0,0 +1,215 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (c) 2023, all rights reserved.
|
4
|
+
|
5
|
+
All the information provided by this platform is protected by international laws related to
|
6
|
+
industrial property, intellectual property, copyright and relative international laws.
|
7
|
+
All intellectual or industrial property rights of the code, texts, trade mark, design,
|
8
|
+
pictures and any other information belongs to the owner of this platform.
|
9
|
+
|
10
|
+
Without the written permission of the owner, any replication, modification,
|
11
|
+
transmission, publication is strictly forbidden.
|
12
|
+
|
13
|
+
For more information read the license file including with this software.
|
14
|
+
|
15
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
16
|
+
// ·
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
// ·
|
21
|
+
import { defineStore } from "pinia"
|
22
|
+
import dayjs from 'dayjs'
|
23
|
+
|
24
|
+
|
25
|
+
// · import lesli stores
|
26
|
+
import { useEvents } from 'LesliCalendar/vue/stores/events'
|
27
|
+
//import { useGuests } from 'lesli_calendar/stores/guests'
|
28
|
+
//import { useUser } from "LesliVue/stores/user"
|
29
|
+
|
30
|
+
|
31
|
+
// ·
|
32
|
+
export const useCalendar = defineStore("calendar.calendar", {
|
33
|
+
state: () => {
|
34
|
+
|
35
|
+
return {
|
36
|
+
title: "",
|
37
|
+
calendar: {},
|
38
|
+
calendarData: {},
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
event_id: '',
|
43
|
+
event: {
|
44
|
+
cloud_driver_catalog_event_types_id: null,
|
45
|
+
title: null,
|
46
|
+
description: '',
|
47
|
+
event_date: new Date(),
|
48
|
+
time_start: null,
|
49
|
+
time_end: null,
|
50
|
+
location: '',
|
51
|
+
url: ''
|
52
|
+
},
|
53
|
+
submit: {
|
54
|
+
event: false,
|
55
|
+
delete: false
|
56
|
+
},
|
57
|
+
lesli: {
|
58
|
+
settings: {
|
59
|
+
currency: {
|
60
|
+
symbol: null
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
},
|
66
|
+
|
67
|
+
actions: {
|
68
|
+
|
69
|
+
setTitle() {
|
70
|
+
|
71
|
+
// if current month show the full date
|
72
|
+
if (this.calendar.getDate().getMonth() == (new Date()).getMonth()) {
|
73
|
+
this.title = this.date2().dateWords().toString()
|
74
|
+
} else {
|
75
|
+
this.title = dayjs(this.calendar.getDate()).locale(I18n.locale).format("MMMM, YYYY")
|
76
|
+
}
|
77
|
+
|
78
|
+
},
|
79
|
+
|
80
|
+
todayMonth() {
|
81
|
+
this.calendar.today()
|
82
|
+
this.setTitle()
|
83
|
+
},
|
84
|
+
|
85
|
+
prevMonth() {
|
86
|
+
this.calendar.prev()
|
87
|
+
this.setTitle()
|
88
|
+
},
|
89
|
+
|
90
|
+
nextMonth() {
|
91
|
+
this.calendar.next()
|
92
|
+
this.setTitle()
|
93
|
+
},
|
94
|
+
|
95
|
+
getCalendar() {
|
96
|
+
this.http.get(this.url.calendar("calendar")).then(result => {
|
97
|
+
|
98
|
+
this.calendarData = result
|
99
|
+
|
100
|
+
this.calendarData.events_support = this.calendarData.events_support.map(event => {
|
101
|
+
return {
|
102
|
+
title: event.subject,
|
103
|
+
start: event.deadline,
|
104
|
+
ticket: event.id,
|
105
|
+
description: event.description,
|
106
|
+
engine: "lesli-support",
|
107
|
+
classNames: "lesli-support"
|
108
|
+
}
|
109
|
+
})
|
110
|
+
|
111
|
+
result.events_support.forEach(event => {
|
112
|
+
this.calendar.addEvent(event)
|
113
|
+
})
|
114
|
+
}).catch(error => {
|
115
|
+
console.log(error)
|
116
|
+
})
|
117
|
+
},
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
reset() {
|
126
|
+
const storeUser = useUser()
|
127
|
+
this.event = {
|
128
|
+
organizer_name: storeUser.user.full_name,
|
129
|
+
cloud_driver_catalog_event_types_id: null,
|
130
|
+
title: null,
|
131
|
+
description: '',
|
132
|
+
event_date: new Date(),
|
133
|
+
time_start: null,
|
134
|
+
time_end: null,
|
135
|
+
location: '',
|
136
|
+
url: ''
|
137
|
+
}
|
138
|
+
},
|
139
|
+
|
140
|
+
async postEvent(url = this.url.driver('events')) {
|
141
|
+
const storeEvent = useEvent();
|
142
|
+
let data = { event: this.event};
|
143
|
+
this.submit.event = true
|
144
|
+
try {
|
145
|
+
const result = await this.http.post(url, data).then(event => {
|
146
|
+
this.event_id = event.id
|
147
|
+
let newEvent = {
|
148
|
+
...event,
|
149
|
+
date: event.event_date,
|
150
|
+
start: event.time_start,
|
151
|
+
end: event.time_end
|
152
|
+
}
|
153
|
+
this.calendarData.driver_events.push(newEvent);
|
154
|
+
this.calendarData.events.push(newEvent);
|
155
|
+
this.calendar.addEvent(newEvent)
|
156
|
+
});
|
157
|
+
storeEvent.showModal = !storeEvent.showModal;
|
158
|
+
this.msg.success(I18n.t("core.users.messages_success_operation"));
|
159
|
+
} catch (error) {
|
160
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"));
|
161
|
+
} finally {
|
162
|
+
this.submit.event = false
|
163
|
+
}
|
164
|
+
},
|
165
|
+
|
166
|
+
async putEvent(url = this.url.driver(`events/${this.event.id}`)) {
|
167
|
+
const storeEvent = useEvent()
|
168
|
+
let data = { event: this.event }
|
169
|
+
this.submit.event = true
|
170
|
+
try {
|
171
|
+
const result = await this.http.put(url, data)
|
172
|
+
let oldEvent = this.calendar.getEventById(this.event_id)
|
173
|
+
let updatedEvent = {
|
174
|
+
...this.event,
|
175
|
+
date: this.event.event_date,
|
176
|
+
start: this.event.time_start,
|
177
|
+
end: this.event.time_end,
|
178
|
+
}
|
179
|
+
oldEvent.remove()
|
180
|
+
this.calendar.addEvent(updatedEvent)
|
181
|
+
this.msg.success(I18n.t("core.users.messages_success_operation"))
|
182
|
+
storeEvent.showModal = !storeEvent.showModal
|
183
|
+
} catch (error) {
|
184
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
185
|
+
} finally {
|
186
|
+
this.submit.event = false
|
187
|
+
}
|
188
|
+
},
|
189
|
+
|
190
|
+
async deleteEvent() {
|
191
|
+
const storeEvent = useEvent()
|
192
|
+
const { isConfirmed } = await this.dialog.confirmation({
|
193
|
+
title: "Delete event",
|
194
|
+
text: "driver.events.view_text_delete_confirmation",
|
195
|
+
confirmText: I18n.t("core.shared.view_text_yes"),
|
196
|
+
cancelText: I18n.t("core.shared.view_text_no")
|
197
|
+
})
|
198
|
+
|
199
|
+
if (isConfirmed) {
|
200
|
+
try {
|
201
|
+
storeEvent.submit.delete = true
|
202
|
+
const result = await this.http.delete(this.url.driver(`events/${this.event_id}`))
|
203
|
+
let deletedEvent = this.calendar.getEventById(this.event_id)
|
204
|
+
deletedEvent.remove()
|
205
|
+
this.msg.success(I18n.t("core.users.messages_success_operation"))
|
206
|
+
storeEvent.showModal = !storeEvent.showModal
|
207
|
+
} catch (error) {
|
208
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
209
|
+
}
|
210
|
+
}
|
211
|
+
storeEvent.submit.delete = false
|
212
|
+
return { isConfirmed }
|
213
|
+
}
|
214
|
+
}
|
215
|
+
})
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
|
3
|
+
Copyright (c) 2023, all rights reserved.
|
4
|
+
|
5
|
+
All the information provided by this platform is protected by international laws related to
|
6
|
+
industrial property, intellectual property, copyright and relative international laws.
|
7
|
+
All intellectual or industrial property rights of the code, texts, trade mark, design,
|
8
|
+
pictures and any other information belongs to the owner of this platform.
|
9
|
+
|
10
|
+
Without the written permission of the owner, any replication, modification,
|
11
|
+
transmission, publication is strictly forbidden.
|
12
|
+
|
13
|
+
For more information read the license file including with this software.
|
14
|
+
|
15
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
16
|
+
// ·
|
17
|
+
|
18
|
+
*/
|
19
|
+
|
20
|
+
// ·
|
21
|
+
import { defineStore } from "pinia"
|
22
|
+
|
23
|
+
// ·
|
24
|
+
export const useEvents = defineStore("driver.events", {
|
25
|
+
state: () => {
|
26
|
+
return {
|
27
|
+
showModal: false,
|
28
|
+
options: {
|
29
|
+
event_types: []
|
30
|
+
},
|
31
|
+
submit: {
|
32
|
+
event: false,
|
33
|
+
delete: false
|
34
|
+
},
|
35
|
+
}
|
36
|
+
},
|
37
|
+
|
38
|
+
actions: {
|
39
|
+
|
40
|
+
getOptions() {
|
41
|
+
let url = this.url.driver('events/options')
|
42
|
+
this.http.get(url).then(result => {
|
43
|
+
if (result) {
|
44
|
+
this.options.event_types = result.event_types.map(option => {
|
45
|
+
return { label: option.text, value: option.value };
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}).catch(error => {
|
49
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
50
|
+
})
|
51
|
+
},
|
52
|
+
}
|
53
|
+
})
|
@@ -0,0 +1,213 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2023, all rights reserved.
|
3
|
+
|
4
|
+
All the information provided by this platform is protected by international laws related to
|
5
|
+
industrial property, intellectual property, copyright and relative international laws.
|
6
|
+
All intellectual or industrial property rights of the code, texts, trade mark, design,
|
7
|
+
pictures and any other information belongs to the owner of this platform.
|
8
|
+
|
9
|
+
Without the written permission of the owner, any replication, modification,
|
10
|
+
transmission, publication is strictly forbidden.
|
11
|
+
|
12
|
+
For more information read the license file including with this software.
|
13
|
+
|
14
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
15
|
+
// ·
|
16
|
+
*/
|
17
|
+
|
18
|
+
// ·
|
19
|
+
import { defineStore } from "pinia"
|
20
|
+
import { useCalendar } from 'LesliCalendar/stores/calendar'
|
21
|
+
|
22
|
+
// · import lesli stores
|
23
|
+
import { useUsers } from "LesliVue/stores/users"
|
24
|
+
|
25
|
+
// ·
|
26
|
+
export const useGuests = defineStore("driver.guests", {
|
27
|
+
state: () => {
|
28
|
+
return {
|
29
|
+
main_route: `/driver/events`,
|
30
|
+
attendant_options: {
|
31
|
+
users: []
|
32
|
+
},
|
33
|
+
attendants: [],
|
34
|
+
guest: {
|
35
|
+
name: "",
|
36
|
+
email: "",
|
37
|
+
},
|
38
|
+
lists_synched: false,
|
39
|
+
loading: {
|
40
|
+
attendants: false,
|
41
|
+
options: false
|
42
|
+
},
|
43
|
+
loaded: {
|
44
|
+
attendants: false,
|
45
|
+
attendant_options: false
|
46
|
+
},
|
47
|
+
submit: {
|
48
|
+
event: false,
|
49
|
+
delete: false,
|
50
|
+
guest: false
|
51
|
+
},
|
52
|
+
|
53
|
+
translations: {
|
54
|
+
main: I18n.t('driver.events'),
|
55
|
+
core: I18n.t('core.shared'),
|
56
|
+
core_users: I18n.t('core.users')
|
57
|
+
}
|
58
|
+
}
|
59
|
+
},
|
60
|
+
|
61
|
+
actions: {
|
62
|
+
|
63
|
+
getUsers() {
|
64
|
+
const storeUsers = useUsers()
|
65
|
+
try {
|
66
|
+
this.loading.attendants = false
|
67
|
+
this.attendant_options.users = storeUsers.list.map(user => {
|
68
|
+
const foundAttendant = this.attendants.find(attendant => attendant.email === user.email);
|
69
|
+
return {
|
70
|
+
id: user.id,
|
71
|
+
name: user.name,
|
72
|
+
email: user.email,
|
73
|
+
checked: !!foundAttendant
|
74
|
+
};
|
75
|
+
});
|
76
|
+
} catch (error) {
|
77
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
78
|
+
} finally {
|
79
|
+
this.loaded.attendant_options = true
|
80
|
+
}
|
81
|
+
},
|
82
|
+
|
83
|
+
getAttendants() {
|
84
|
+
const storeCalendar = useCalendar()
|
85
|
+
let url = `${this.main_route}/${storeCalendar.event.id}/attendants.json`
|
86
|
+
this.loading.attendants = true
|
87
|
+
this.http.get(url).then(result => {
|
88
|
+
this.loading.attendants = false
|
89
|
+
const filteredAttendant = result.filter((attendant, index, self) =>
|
90
|
+
self.findIndex(record => record.email === attendant.email) === index
|
91
|
+
)
|
92
|
+
this.attendants = filteredAttendant
|
93
|
+
}).catch(error => {
|
94
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
95
|
+
}).finally(() => {
|
96
|
+
this.loaded.attendants = true
|
97
|
+
})
|
98
|
+
},
|
99
|
+
|
100
|
+
|
101
|
+
postAttendant(user) {
|
102
|
+
const storeCalendar = useCalendar()
|
103
|
+
let url = this.url.driver("events/:event_id/attendants", { event_id: storeCalendar.event.id })
|
104
|
+
let data = {
|
105
|
+
event_attendant: {
|
106
|
+
users_id: user.id
|
107
|
+
}
|
108
|
+
}
|
109
|
+
this.http.post(url, data).then(result => {
|
110
|
+
this.attendants.push({
|
111
|
+
id: result.id,
|
112
|
+
type: 'attendant',
|
113
|
+
name: user.name || user.email,
|
114
|
+
email: user.email,
|
115
|
+
users_id: user.id,
|
116
|
+
confirmed_at_string: null
|
117
|
+
})
|
118
|
+
this.msg.success(this.translations.main.messages_success_attendant_created)
|
119
|
+
|
120
|
+
}).catch(error => {
|
121
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
122
|
+
})
|
123
|
+
},
|
124
|
+
|
125
|
+
postGuest() {
|
126
|
+
const storeCalendar = useCalendar()
|
127
|
+
let url = this.url.driver("events/:event_id/guests", { event_id: storeCalendar.event.id })
|
128
|
+
this.submit.guest = true
|
129
|
+
|
130
|
+
this.http.post(url, {
|
131
|
+
event_guest: this.guest
|
132
|
+
}).then(result => {
|
133
|
+
this.attendants.push({
|
134
|
+
...result,
|
135
|
+
type: 'guest',
|
136
|
+
name: result.name || result.email,
|
137
|
+
})
|
138
|
+
this.guest = {}
|
139
|
+
this.msg.success(this.translations.main.messages_success_attendant_created)
|
140
|
+
|
141
|
+
}).catch(error => {
|
142
|
+
this.msg.danger(this.translations.core.shared.messages_danger_internal_error);
|
143
|
+
}).finally(() => {
|
144
|
+
this.submit.guest = false
|
145
|
+
})
|
146
|
+
},
|
147
|
+
|
148
|
+
confirmAttendance(user, today) {
|
149
|
+
const storeCalendar = useCalendar();
|
150
|
+
let url, data;
|
151
|
+
|
152
|
+
this.loading.attendants = true;
|
153
|
+
|
154
|
+
if (user.users_id) {
|
155
|
+
url = this.url.driver("events/:event_id/attendants/:attendant_id", {
|
156
|
+
event_id: storeCalendar.event.id,
|
157
|
+
attendant_id: user.id
|
158
|
+
});
|
159
|
+
data = { event_attendant: user };
|
160
|
+
} else {
|
161
|
+
url = this.url.driver("events/:event_id/guests/:attendant_id", {
|
162
|
+
event_id: storeCalendar.event.id,
|
163
|
+
attendant_id: user.id
|
164
|
+
});
|
165
|
+
data = { event_guest: user };
|
166
|
+
}
|
167
|
+
|
168
|
+
this.http.put(url, data)
|
169
|
+
.then(result => {
|
170
|
+
const attendantIndex = this.attendants.findIndex(attendant => attendant.email === user.email);
|
171
|
+
this.attendants[attendantIndex].confirmed_at_string = today;
|
172
|
+
this.msg.success(this.translations.core_users.messages_success_operation);
|
173
|
+
})
|
174
|
+
.catch(error => {
|
175
|
+
this.msg.danger(this.translations.core.shared.messages_danger_internal_error);
|
176
|
+
})
|
177
|
+
.finally(() => {
|
178
|
+
this.loading.attendants = false;
|
179
|
+
});
|
180
|
+
},
|
181
|
+
|
182
|
+
deleteInvite(user) {
|
183
|
+
const storeCalendar = useCalendar()
|
184
|
+
|
185
|
+
const index = this.attendant_options.users.findIndex(attendant => attendant.email === user.email);
|
186
|
+
if (index !== -1) {
|
187
|
+
this.attendant_options.users[index].checked = false;
|
188
|
+
}
|
189
|
+
|
190
|
+
let attendant = this.attendants.find(attendant => {
|
191
|
+
return attendant.email === user.email
|
192
|
+
})
|
193
|
+
let url = `${this.main_route}/${storeCalendar.event.id}/attendants/${attendant.id}.json`
|
194
|
+
|
195
|
+
// If this is a guest, we have a different endpoint
|
196
|
+
if (user.type == 'guest') {
|
197
|
+
url = `${this.main_route}/${storeCalendar.event.id}/guests/${attendant.id}.json`
|
198
|
+
}
|
199
|
+
this.submit.delete = true
|
200
|
+
this.http.delete(url).then(result => {
|
201
|
+
this.attendants = this.attendants.filter((attendant) => {
|
202
|
+
return attendant.email !== user.email
|
203
|
+
})
|
204
|
+
|
205
|
+
this.msg.success(this.translations.main.messages_success_attendant_deleted)
|
206
|
+
}).catch(error => {
|
207
|
+
this.msg.danger(I18n.t("core.shared.messages_danger_internal_error"))
|
208
|
+
}).finally(() => {
|
209
|
+
this.submit.delete = false
|
210
|
+
})
|
211
|
+
},
|
212
|
+
}
|
213
|
+
})
|