-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutil.js
67 lines (56 loc) · 1.6 KB
/
util.js
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
var _ = require('lodash');
var Util = function (options) {
this.cellData = options.cellData;
};
Util.prototype.groupStates = function (stateList) {
stateList.forEach(function (state) {
if (!state.external) {
if (!state.pendingGroup) {
state.pendingGroup = {};
}
stateList.forEach(function (memberState) {
state.pendingGroup[memberState.id] = memberState;
});
}
});
};
Util.prototype.ungroupStates = function (stateList) {
var self = this;
stateList.forEach(function (state) {
if (!state.external && state.pendingGroup) {
stateList.forEach(function (memberState) {
delete state.pendingGroup[memberState.id];
if (_.isEmpty(state.pendingGroup)) {
delete state.pendingGroup;
}
});
}
});
};
Util.prototype.ungroupStateFromAll = function (state) {
var self = this;
var groupMembers = state.pendingGroup || {};
var stateUngroupList = [];
Object.keys(groupMembers).forEach(function (memberId) {
var cellIndex = state.ccid;
var type = state.type;
var memberSimpleState = groupMembers[memberId];
if (self.cellData[cellIndex] && self.cellData[cellIndex][type]) {
var memberState = self.cellData[cellIndex][type][memberId];
if (memberState) {
stateUngroupList.push(memberState);
}
}
});
self.ungroupStates(stateUngroupList);
};
Util.prototype.removeByVal = function(array, val) {
for (var i = 0; i < array.length; i++) {
if (array[i] === val) {
array.splice(i, 1);
i--;
}
}
return this;
}
module.exports.Util = Util;