blob: 255275f7067d875cb72382974eb07aa523a587a8 (
plain)
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
85
86
87
88
89
90
|
import * as types from '../../types'
import { store } from '../../store'
import actions from '../../actions'
import { default as debounce } from 'lodash.debounce'
export const showAddTileForm = () => dispatch => {
dispatch({ type: types.page.show_add_tile_form })
}
export const hideAddTileForm = () => dispatch => {
dispatch({ type: types.page.hide_add_tile_form })
}
export const toggleAddTileForm = () => dispatch => {
dispatch({ type: types.page.toggle_add_tile_form })
}
export const showEditTileForm = tile_id => dispatch => {
dispatch({ type: types.page.show_edit_tile_form, tile_id })
}
export const hideEditTileForm = () => dispatch => {
dispatch({ type: types.page.hide_edit_tile_form })
}
export const toggleEditTileForm = () => dispatch => {
dispatch({ type: types.page.toggle_edit_tile_form })
}
export const showTileList = () => dispatch => {
dispatch({ type: types.page.show_tile_list })
}
export const hideTileList = () => dispatch => {
dispatch({ type: types.page.hide_tile_list })
}
export const toggleTileList = () => dispatch => {
dispatch({ type: types.page.toggle_tile_list })
}
export const updatePageTile = tile => dispatch => {
dispatch({ type: types.page.update_page_tile, tile })
}
export const showGraphAndPageIfUnloaded = ({ graph_name, page_name }) => dispatch => (
new Promise((resolve, reject) => {
showGraphIfUnloaded({ graph_name })(dispatch)
.then(graph => (
actions.page.show('name/' + graph_name + '/' + page_name)
.then(resolve)
.catch(reject)
))
.catch(reject)
})
)
export const showGraphIfUnloaded = ({ graph_name }) => dispatch => (
new Promise((resolve, reject) => {
const { res: graph } = store.getState().graph.show
if (graph && graph.path === graph_name) {
return resolve(graph)
}
actions.graph.show('name/' + graph_name)
.then(resolve)
.catch(reject)
})
)
export const setTileSortOrder = (tiles) => dispatch => {
dispatch({ type: types.page.set_tile_sort_order, tiles })
updateTileSortOrder(tiles)
}
export const isSameTileOrder = (newTiles, oldTiles) => {
for (let i = 0; i < newTiles.length; i++) {
if (newTiles[i].id !== oldTiles[i].id) {
return false
}
}
return true
}
export const updateTileSortOrder = debounce((tiles) => {
let oldTiles = store.getState().page.show.res.tiles
if (isSameTileOrder(tiles, oldTiles)) return
console.log('update tile sort order')
const newOrder = tiles.map((tile, i) => ({ id: tile.id, sort_order: i }))
console.log(newOrder)
}, 1000)
|