forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwm.js
84 lines (68 loc) · 1.65 KB
/
wm.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { addObject, removeObject } from '@/utils/array';
export const state = function() {
return {
tabs: [],
active: null,
open: false,
userHeight: null,
};
};
export const getters = {
byId: state => (id) => {
return state.tabs.find(x => x.id === id);
}
};
export const mutations = {
addTab(state, tab) {
const existing = state.tabs.find(x => x.id === tab.id);
if ( !existing ) {
addObject(state.tabs, tab);
}
state.active = tab.id;
state.open = true;
},
removeTab(state, tab) {
removeObject(state.tabs, tab);
},
setOpen(state, open) {
state.open = open;
},
setActive(state, id) {
state.active = id;
},
setUserHeight(state, height) {
state.userHeight = height;
}
};
export const actions = {
close({ state, getters, commit }, id) {
const tab = getters.byId(id);
if ( !tab ) {
return;
}
let idx = state.tabs.indexOf(tab);
commit('removeTab', tab);
if ( idx >= state.tabs.length ) {
idx = state.tabs.length - 1;
}
if ( idx >= 0 ) {
commit('setActive', state.tabs[idx].id);
} else {
commit('setOpen', false);
}
},
// {
// id: shell-<pod id> -- A string that is be unique for this instance;
// if a window with this key exists it will be focused instead of creating another
// label: Shown on the tab
// icon: Shown on the tab
// component: 'ContainerShell',
// attrs: { whateverTheComponent: wants }
// }
open({ commit }, tab) {
if ( !tab.id ) {
throw new Error('Window must have an id property');
}
commit('addTab', tab);
}
};