Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
171 lines (152 loc) · 3.81 KB
/
Copy pathutils.js
File metadata and controls
171 lines (152 loc) · 3.81 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
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
import login from '@/gql/login.gql'
import { DateTime } from 'luxon'
export const calculateExpiresIn = (timestamp) =>
(timestamp - Math.floor(Date.now() / 1000)) / (3600 * 24)
const TOAST_LENGTH = 4000
export async function userLogin(vueInstance, email, password) {
try {
const res = await vueInstance.$apollo.mutate({
mutation: login,
variables: {
input: {
email,
password,
},
},
})
const userData = res.data.login.user
const expiresIn = calculateExpiresIn(res.data.login.refreshExpiresIn)
vueInstance.$store.dispatch('user_data/onLogin', {
userData,
expiresIn,
})
await vueInstance.$apolloHelpers
.onLogin(res.data.login.token, undefined, {
expires: expiresIn,
})
.then(() => {
window.location = '/'
})
} catch (error) {
vueInstance.$nuxt.error({
statusCode: 401,
message: error,
})
}
}
export const staffToString = ({ firstName, lastName, title }) => {
const titleMapping = {
DR: 'ד״ר',
PR: 'פרופ׳',
MR: 'מר',
MS: 'גב׳',
}
if (!(title in titleMapping)) {
return ''
}
return `${titleMapping[title]} ${firstName} ${lastName}`
}
export const multipleStaffToString = (arr) => {
return arr.map((item) => staffToString(item.node)).join(', ')
}
export const getSemester = ({ name, yearJewish }) => {
const semesterName = name === 'A' ? 'א׳' : name === 'B' ? 'ב׳' : 'קיץ'
return `${semesterName} ${yearJewish}`
}
export const mergeCurrentSemesterCoursesData = (oldData, newData) => {
const ret = { ...newData }
ret.__typename = oldData.__typename
ret.allCourses.edges = [...oldData.allCourses.edges, ...ret.allCourses.edges]
return ret
}
export const currentSemesterCourseDataTransform = (data) => {
const allCourses = data.allCourses.edges
const dataArray = []
const { endCursor, hasNextPage } = data.allCourses.pageInfo
for (const course of allCourses) {
dataArray.push(course.node)
}
return {
dataArray,
endCursor,
hasNextPage,
}
}
export const myCoursesDataTransform = (data) => {
const allData = data.currentUser.userCourses
const dataArray = allData.edges.map((item) => item.node)
const { endCursor, hasNextPage } = allData.pageInfo
return {
dataArray,
endCursor,
hasNextPage,
}
}
export const mergeMyCoursesData = (oldData, newData) => {
const ret = {
...newData,
}
ret.__typename = oldData.__typename
ret.currentUser.userCourses.edges = [
...oldData.currentUser.userCourses.edges,
...newData.currentUser.userCourses.edges,
]
return ret
}
export const roleParser = (toParse) => {
switch (toParse) {
case 'A_1':
return 'משתמש'
case 'A_2':
return 'עורך תוכן'
case 'A_3':
return 'מנהל'
default:
return toParse
}
}
export const XOR = (a, b) => {
return (a || b) && !(a && b)
}
export const showSuccessToast = (
vm,
message,
link = null,
onCompleteHook = null
) => {
vm.$toast.success(message, {
position: 'bottom-left',
duration: TOAST_LENGTH,
onComplete: () => {
if (onCompleteHook !== null) {
onCompleteHook()
}
if (link !== null) {
vm.$router.push(link)
}
},
})
}
export const showErrorToast = (
vm,
message,
link = null,
onCompleteHook = null
) => {
vm.$toast.error(message, {
position: 'bottom-left',
duration: TOAST_LENGTH,
onComplete: () => {
if (onCompleteHook !== null) {
onCompleteHook()
}
if (link !== null) {
vm.$router.push(link)
}
},
})
}
export const getDate = (date) =>
DateTime.fromISO(date).setLocale('he').toLocaleString(DateTime.DATE_SHORT)
export const trimLength = (message, length = 40) =>
message.slice(0, length) + (message.length > length ? '...' : '')