1
|
|
|
import { |
2
|
|
|
cmsData |
3
|
|
|
,config |
4
|
|
|
} from '../../' |
5
|
|
|
|
6
|
|
|
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') { |
7
|
|
|
let meta = config.meta.name |
8
|
|
|
|
9
|
|
|
var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date() |
10
|
|
|
var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + '' |
11
|
|
|
|
12
|
|
|
if(typeof json[meta].date === 'undefined' || json[meta].date === null) { |
13
|
|
|
json[meta].date = currentDate |
14
|
|
|
} |
15
|
|
|
json[meta].latest = { |
16
|
|
|
date: currentDate, |
17
|
|
|
abeUrl: abeUrl |
18
|
|
|
} |
19
|
|
|
json[meta].status = realType === 'reject' ? 'draft' : realType |
20
|
|
|
if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) { |
21
|
|
|
json[meta][type] = JSON.parse(JSON.stringify(obj)) |
22
|
|
|
json[meta][type].date = currentDate |
23
|
|
|
json[meta][type].abeUrl = abeUrl |
24
|
|
|
} |
25
|
|
|
json[meta][type].latest = JSON.parse(JSON.stringify(obj)) |
26
|
|
|
json[meta][type].latest.date = currentDate |
27
|
|
|
json[meta][type].latest.abeUrl = abeUrl |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
export function get(arr) { |
31
|
|
|
var res = [] |
32
|
|
|
Array.prototype.forEach.call(arr, (file) => { |
33
|
|
|
let meta = config.meta.name |
34
|
|
|
|
35
|
|
|
var jsonPath = cmsData.file.fromUrl(file.path).json.path |
36
|
|
|
var json = cmsData.file.get(jsonPath) |
37
|
|
|
if(typeof json[meta] === 'undefined' || json[meta] === null) json[meta] = {} |
|
|
|
|
38
|
|
|
file['template'] = json[meta].template |
39
|
|
|
if(typeof json[meta].latest !== 'undefined' && json[meta].latest !== null) { |
40
|
|
|
file['date'] = json[meta].latest.date |
41
|
|
|
} |
42
|
|
|
if(typeof json[meta].complete === 'undefined' || json[meta].complete === null) { |
43
|
|
|
json[meta].complete = 0 |
44
|
|
|
} |
45
|
|
|
if(typeof json[meta] !== 'undefined' && json[meta] !== null) { |
46
|
|
|
file[config.meta.name] = json[meta] |
47
|
|
|
} |
48
|
|
|
res.push(file) |
49
|
|
|
}) |
50
|
|
|
|
51
|
|
|
return res |
52
|
|
|
} |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.