-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.js
More file actions
143 lines (130 loc) · 5.17 KB
/
Course.js
File metadata and controls
143 lines (130 loc) · 5.17 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
/*eslint-env node, es6*/
/*eslint no-console:1*/
const path = require('path');
const Logger = require('logger');
var logger = new Logger('Conversion Report');
function getAccountID(data) {
var isAllNumbers = /^\d+$/;
var numberOut;
if(data.platform === "online") {
numberOut = '42';
}
else if (data.canvasAccountID !== undefined && typeof data.canvasAccountID === "string" && isAllNumbers.test(data.canvasAccountID)) {
numberOut = data.canvasAccountID;
} else{
numberOut = "19";
}
console.log(numberOut);
return numberOut;
}
module.exports = class Course {
constructor(data) {
this.settings = {
'domain': data.domain || 'byui',
'platform': data.platform || 'online',
'accountID': getAccountID(data),
'cookies': data.cookies || [],
'deleteCourse': data.cleanUpModules ? data.cleanUpModules.includes('delete-course') : false,
'removeFiles': data.cleanUpModules ? !data.cleanUpModules.includes('remove-files') : true,
'reorganizeFiles': false,
'lessonFolders': false,
'pinDiscussionBoards': false,
'blockCourse': /block/i.test(data.name),
'targetAttributes': false,
'disableLogOutput': false,
'blueprintLockItems': false,
'moveUnusedIntoArchive': false,
'renameFiles': false,
'moveFiles': false,
'moduleItemNamingConventions': false,
'term': data.EnrollmentTerm || null
};
/* Identify the selected options and add them to settings */
if (data.options) {
data.options.forEach(option => {
this.settings[option.name] = option.value;
});
}
/* Add leading 20 to enrollment term year. This will break in 900+ years */
if (this.settings.term) {
this.settings.term = this.settings.term.replace(/\d+/, '20$&');
}
this.info = {
'data': data,
'username': data.username || data.author || 'Unspecified',
'password': data.password || null,
'instructorName': data.instructorName || '',
'instructorEmail': data.instructorEmail || '',
'D2LOU': data.D2LOU || '',
'originalZipPath': data.name ? path.resolve('factory', 'originalZip', data.name) : 'Unspecified',
'unzippedPath': path.resolve('factory', 'unzipped') || 'Unspecified',
'processedPath': path.resolve('factory', 'processed') || 'Unspecified',
'uploadZipPath': path.resolve('factory', 'uploadZip') || 'Unspecified',
'fileName': data.name ? data.name.split(path.sep)[data.name.split(path.sep).length - 1].replace('\\', '-').replace('/', '-') : 'Unspecified',
'childModules': data.preImportModules && data.postImportModules ? [...data.preImportModules, ...data.postImportModules] : [],
'canvasOU': data.canvasOU || '',
'checkStandards:': false,
'linkCounter': 0,
'canvasFolders': {
media: -1,
documents: -1,
template: -1,
archive: -1
},
get counter() {
this.linkCounter = this.linkCounter++;
return this.linkCounter;
}
};
this.info.courseName = this.info.fileName.split('.zip')[0];
this.info.courseCode = (this.info.fileName.split(' ')[0] + ' ' + this.info.fileName.split(' ')[1]).replace(':', '');
this.info.courseCode = this.info.courseCode.replace('.zip', '');
// console.log('COURSE NAME:', this.info.courseName);
// console.log('COURSE CODE:', this.info.courseCode);
/* Set up the logger */
this.logger = logger;
this.logs = logger.logs;
this.content = [];
this.log = logger.log;
this.warning = logger.warning;
this.error = logger.error;
this.fatalError = logger.fatalError;
this.message = logger.message;
//console.log(logger.message);
this.getCallingModule = logger.getCallingModule;
this.console = logger.console;
/* Disable output if set */
if (this.settings.disableLogOutput === true) {
logger.disableOutput(true);
console.log('LOGGER OUTPUT DISABLED');
}
/* Removes new lines in the logs */
logger.removeNewLines(true);
}
/* Adds new "junk drawer" item to info */
newInfo(propertyName, value) {
if (this.info[propertyName]) {
// eslint-disable-next-line
console.log(`This item already exists on the course.info object. Cannot add: ${propertyName}`);
} else {
this.info[propertyName] = value;
}
}
/* Retrieves the current count on linkCounter */
getCount() {
this.info.linkCounter += 1;
return this.info.linkCounter;
}
consoleReport() {
logger.consoleReport();
}
jsonReport(path) {
logger.jsonReport(path);
}
htmlReport(location, title) {
logger.htmlReport(location, title);
}
setReportHeader(html) {
logger.setHtmlHeader(html);
}
};