-
Notifications
You must be signed in to change notification settings - Fork 70
/
main.controller.js
67 lines (61 loc) · 1.17 KB
/
main.controller.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
/**
* @typedef {{type:string}} Item
* @typedef {{items: Item[]}} FormConfig
*/
class MainController {
/**
* @ngInject
*/
constructor() {
/**
* @type {FormConfig}
*/
this.form = {
items: [],
}
}
/**
* Add new Item
* @param {string} type
*/
addItem(type) {
this.form.items.push({
type,
})
}
/**
* Remove item at index
* @param {Item} item
* @param {number} index
*/
delete(item, index) {
this.form.items.splice(index, 1)
}
/**
* insert before (bounded)
* Pops out latest element (wanted?)
* @param {Item} item
* @param {number} index
*/
up(item, index) {
if (index !== 0) {
const prevItem = this.form.items[index - 1]
this.form.items[index] = prevItem
this.form.items[index - 1] = item
}
}
/**
* insert after (bounded)
* Pops out latest element (wanted?)
* @param {Item} item
* @param {number} index
*/
down(item, index) {
if (index !== this.form.items.length - 1) {
const nextItem = this.form.items[index + 1]
this.form.items[index] = nextItem
this.form.items[index + 1] = item
}
}
}
export { MainController }