forked from Qihoo360/wayne
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.service.ts
More file actions
47 lines (40 loc) · 1.19 KB
/
diff.service.ts
File metadata and controls
47 lines (40 loc) · 1.19 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
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { DiffTpl } from './diff';
import { MessageHandlerService } from '../message-handler/message-handler.service';
const defaultTmp: DiffTpl = {
fileName: '',
oldStr: '',
newStr: '',
oldHeader: 'before',
newHeader: 'after'
};
@Injectable()
export class DiffService {
constructor(
private messageHandlerService: MessageHandlerService
) {
}
diffSub = new Subject<DiffTpl>();
diffOb = this.diffSub.asObservable();
diff(selected: any[], tmpPropName = 'template', namePropName = 'id') {
const length = selected.length;
let diffTpl;
if (length < 2) {
this.messageHandlerService.showError('SHARED.DIFF.TMP_LESS');
return;
} else {
diffTpl = {
oldStr: selected[1][tmpPropName],
newStr: selected[0][tmpPropName],
oldHeader: `${selected[0][namePropName]}`,
newHeader: `${selected[1][namePropName]}`
};
if (length > 2) {
this.messageHandlerService.showInfo('SHARED.DIFF.TMP_MORE');
}
}
diffTpl = { ...defaultTmp, ...diffTpl };
this.diffSub.next(diffTpl);
}
}