-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.example.ts
179 lines (165 loc) · 5.46 KB
/
config.example.ts
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
172
173
174
175
176
177
178
179
/* eslint-disable @typescript-eslint/no-use-before-define */
import Catalog, { SemesterJSON } from './models/Catalog';
import Course from './models/Course';
import Section from './models/Section';
/** the version string from package.json */
export const version: string = require('../package.json').version;
/** whether running on electron */
export const runningOnElectron = window.navigator.userAgent.toLowerCase().includes('electron');
export interface BackendConfig {
/** Name of the backend */
name: string;
/** API endpoint for uploading/overwriting profiles on remote*/
up: string;
/** API endpoint for downloading profiles from remote */
down: string;
/** API endpoint for editing the properties of the profile (e.g. name) */
edit: string;
/** API endpoint for getting the authorization code */
code: string;
/** API endpoint to exchange authorization code for an access token */
token: string;
/** Client ID for OAuth */
client_id: string;
/** Whether to allow OAuth on plannable desktop app (built with electron) */
oauth_on_electron: false;
/**
* Redirect URI for plannable desktop app. This URI will not be visited. Instead, it acts like a flag, indicating that the server
* has directed back to the client. This can set to anything, as long as the server and the client have an agreement.
* It is recommended to set this value to a (probably non-existent) localhost URI.
*/
oauth_electron_redirect_uri: string;
}
export interface DataEnd {
/**
* an async function that fetches the array of building names
*/
readonly buildings: () => Promise<string[]>;
/**
* an async function that fetches the distance matrix (equivalently, the walking time) between the buildings.
* matrix[i * len + j] represents the distance between the ith building and jth building in the array of buildings fetched by dataend.buildings
* @returns the distance matrix, in Int32Array
*/
readonly distances: () => Promise<Int32Array>;
/**
* an async function that fetches the list of the semesters
*/
readonly semesters: () => Promise<SemesterJSON[]>;
/**
* an async function that fetches all courses corresponding to the given semester
* @returns a catalog object built from the courses
*/
readonly courses: (semester: SemesterJSON) => Promise<Catalog>;
}
/**
* Functions for fetching data
*/
export const dataend: DataEnd = {
buildings: null,
distances: null,
semesters: null,
courses: null
} as any; // remove to enable type checking
interface ModalLinkItem<T> {
/** the inner text of the button used to open your link */
name: string;
/**
* an action to perform when user clicks on this link
* @param semester the currently selected semester
* @param param course/section corresponding to the active modal
*/
action(semester: SemesterJSON, param: T): void;
}
export interface ModalLinks {
section: ModalLinkItem<Section>[];
course: ModalLinkItem<Course>[];
}
/**
* Used to generate a list of action buttons in section/course modal.
* We used it to open external pages relevant to the given course/section.
*/
export const modalLinks: ModalLinks = {
section: [],
course: []
};
/**
* Given an address, convert it to an link to the map (e.g. Google map)
* @returns an url or an empty string
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function formatLocationURL(addr: string) {
return '';
}
/**
* some default UI configurations. Usually no need to change
*/
export const ui = {
sideBarWidth: 19,
sideMargin: 3,
tabBarWidthMobile: 10,
tabBarWidth: 3
} as const;
/**
* expiration config, usually no need to change
*/
export const semesterListExpirationTime = 86400 * 1000; // one day
export const semesterDataExpirationTime = 2 * 3600 * 1000; // two hours
// -------------------------- lecture type configuration ---------------------------------
export type CourseType = keyof typeof TYPES_PARSE;
// CourseStatus is only used for typing purposes. can be just an alias of string
export type CourseStatus = 'TBA' | 'Open' | 'Closed' | 'Wait List';
/**
* lecture type number => meaning
*/
export const TYPES = Object.freeze({
'-1': '',
0: 'Clinical',
1: 'Discussion',
2: 'Drill',
3: 'Independent Study',
4: 'Laboratory',
5: 'Lecture',
6: 'Practicum',
7: 'Seminar',
8: 'Studio',
9: 'Workshop'
});
/**
* parse lecture type string to id
*/
export const TYPES_PARSE = Object.freeze({
'': -1,
Clinical: 0,
CLN: 0,
Discussion: 1,
DIS: 1,
Drill: 2,
DRL: 2,
'Independent Study': 3,
IND: 3,
Laboratory: 4,
LAB: 4,
Lecture: 5,
LEC: 5,
Practicum: 6,
PRA: 6,
Seminar: 7,
SEM: 7,
Studio: 8,
STO: 8,
Workshop: 9,
WKS: 9
});
/**
* whether to enable conversion from [[Course.key]] to human readable string.
* It is only used to inform user about the removal of a course when its key does not exist in catalog.
* The regex variable [[keyRegex]] will be used to match [[Course.key]]
* @see [[Course.key]]
*/
export const enableKeyConversion = false;
/**
* the regex used to match the components of [[Course.key]]. It must have three capture groups,
* one for the department string, one for the course number, and one for the course type, corresponding
* to the keys of TYPES
*/
export const keyRegex: typeof enableKeyConversion extends true ? RegExp : null = null;