This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
360 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
const productionPlugns = [] | ||
|
||
if (process.env.NODE_ENV == 'production') | ||
productionPlugns.push(["transform-remove-console", { "exclude": ["error", "warn", "info"] }]); | ||
|
||
module.exports = { | ||
presets: [ | ||
'@vue/cli-plugin-babel/preset' | ||
] | ||
], | ||
plugins: productionPlugns | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export function getMonday(d) { | ||
/** | ||
* Возвращает понедельник текущей недели | ||
*/ | ||
d = getMidnight(d); | ||
var day = d.getDay(), | ||
diff = d.getDate() - day + (day == 0 ? -6 : 1); // adjust when day is sunday | ||
return new Date(d.setDate(diff)); | ||
} | ||
|
||
|
||
export function getMidnight(d) { | ||
/** | ||
* Возвращает начало сегодняшнего дня | ||
*/ | ||
d = new Date(d); | ||
d.setHours(d.getHours() - d.getTimezoneOffset() / 60); | ||
return d; | ||
} | ||
|
||
export function isToday(d, today) { | ||
/** | ||
* Проверяет совпадение дат, но не времени | ||
*/ | ||
d = new Date(d); | ||
today = new Date(today); | ||
let isToday = ( | ||
today.getFullYear() == d.getFullYear() | ||
&& today.getUTCMonth() == d.getUTCMonth() | ||
&& today.getUTCDate() == d.getUTCDate() | ||
); | ||
return isToday; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export async function fetchTimetable(time_start, time_end, group_id) { | ||
/** | ||
* Генерит запрос на получение расписания и возвращает промис с спаршенным ответом в словаре | ||
*/ | ||
var url = new URL(`${process.env.VUE_APP_API_TIMETABLE}/timetable/event/`), | ||
params = { | ||
start: time_start.toISOString().slice(0, 10), | ||
end: time_end.toISOString().slice(0, 10), | ||
limit: 0, | ||
offset: 0, | ||
group_id: group_id | ||
}; | ||
Object.keys(params).forEach(key => url.searchParams.append(key, params[key])) | ||
return fetch(url).then(response => response.json()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export default function retry(callback, times, interval = 1000) { | ||
/** | ||
* Повторяет запрос, если произошла ошибка | ||
* | ||
* | ||
* Пример: | ||
* function randfail() { | ||
* let r = Math.random(); | ||
* console.log(r); | ||
* if (r < 0.9) throw r; | ||
* return r; | ||
* } | ||
* | ||
* let res; | ||
* retry(() => {res = randfail()}, 100, 10) | ||
*/ | ||
if (times > 0) { | ||
try { | ||
callback(); | ||
} catch (error) { | ||
console.error(`Call failed, retrying... (${times} attempts left)`, error); | ||
setTimeout(() => retry(callback, times - 1, interval), interval); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.