diff --git a/UI/package.json b/UI/package.json index 3cfb8ac..2ac5324 100644 --- a/UI/package.json +++ b/UI/package.json @@ -42,7 +42,7 @@ "not ie <= 11", "not op_mini all" ], - "proxy": "http://localhost:6768", + "proxy": "http://localhost:6769", "devDependencies": { "@babel/plugin-proposal-decorators": "^7.4.0", "customize-cra": "^0.2.12", diff --git a/UI/src/components/role-editor/Category.js b/UI/src/components/role-editor/Category.js index 9134092..c615685 100644 --- a/UI/src/components/role-editor/Category.js +++ b/UI/src/components/role-editor/Category.js @@ -33,7 +33,6 @@ class Category extends Component { { category.get('roles_map') - .sortBy(r => r.get('position')) .reverse() .map((r, k) => ) .toArray() diff --git a/UI/src/components/role-editor/CategoryEditor.js b/UI/src/components/role-editor/CategoryEditor.js index 9847b41..40e292f 100644 --- a/UI/src/components/role-editor/CategoryEditor.js +++ b/UI/src/components/role-editor/CategoryEditor.js @@ -24,6 +24,28 @@ export default class CategoryEditor extends Component {
+
+
+ +
+
+ +
+
diff --git a/UI/src/components/role-editor/RoleEditor.sass b/UI/src/components/role-editor/RoleEditor.sass index e3face1..2e7f976 100644 --- a/UI/src/components/role-editor/RoleEditor.sass +++ b/UI/src/components/role-editor/RoleEditor.sass @@ -36,7 +36,16 @@ color: var(--c-white) - + .role-editor__bumpers + position: absolute + top: 10px + right: 10px + display: flex + + &-bump + transition: color 0.15s ease-in-out + &:hover + color: var(--c-white) .role-editor__category box-sizing: border-box diff --git a/UI/src/components/role-editor/actions.js b/UI/src/components/role-editor/actions.js index 4f17431..3be1789 100644 --- a/UI/src/components/role-editor/actions.js +++ b/UI/src/components/role-editor/actions.js @@ -9,7 +9,7 @@ export const constructView = id => async (dispatch, getState) => { const server = getState().servers.get(id) let { viewMap, hasSafeRoles } = getViewMap(server) - viewMap = viewMap.map(c => c.set('mode', Symbol.for('drop'))) + viewMap = viewMap.map((c, idx) => c.set('mode', Symbol.for('drop'))) dispatch({ type: Symbol.for('re: setup'), @@ -115,7 +115,8 @@ export const createCategory = (dispatch, getState) => { let name = 'New Category' let idx = 1 - while (vm.find(c => c.get('name') === name) !== undefined) { + const pred = c => c.get('name') === name + while (vm.find(pred) !== undefined) { idx++ name = `New Category ${idx}` } @@ -131,16 +132,57 @@ export const createCategory = (dispatch, getState) => { roles_map: Set([]), hidden: true, type: 'multi', + position: idx, mode: Symbol.for('edit') } }) } +export const bumpCategory = (category, name) => move => async (dispatch, getState) => { + const { roleEditor } = getState() + const vm = roleEditor.get('viewMap') + + const position = category.get('position') + const nextPos = position + move + + const replaceThisOne = vm.findKey(category => category.get('position') === nextPos) + + dispatch({ + type: Symbol.for('re: edit category'), + data: { + id: name, + key: 'position', + value: nextPos + } + }) + + if (!!replaceThisOne) { + dispatch({ + type: Symbol.for('re: edit category'), + data: { + id: replaceThisOne, + key: 'position', + value: position + } + }) + } + +} + export const saveServer = id => async (dispatch, getState) => { const viewMap = getState().roleEditor.get('viewMap') .filterNot((_, k) => k === 'Uncategorized') .map(v => v.delete('roles_map').delete('mode').delete('id')) + viewMap.map((v, idx) => { + if (v.has('position')) { + return v + } + + console.warn('category position wasnt set, so fake ones are being made', {cat: v.toJS(), idx, position: viewMap.count()+idx}) + return v.set('position', viewMap.count()+idx) + }) + await superagent.patch(`/api/server/${id}`).send({ categories: viewMap.toJS() }) dispatch({ type: Symbol.for('re: swap original state') }) } diff --git a/UI/src/components/role-editor/index.js b/UI/src/components/role-editor/index.js index 6af2fe7..d6d0e0d 100644 --- a/UI/src/components/role-editor/index.js +++ b/UI/src/components/role-editor/index.js @@ -107,6 +107,8 @@ class RoleEditor extends Component { dispatch(Actions.saveServer(server)) } + onBump = (category, name) => (move) => () => this.props.dispatch(Actions.bumpCategory(category, name)(move)) + get hasChanged () { return this.props.editor.get('originalSnapshot').hashCode() !== this.props.editor.get('viewMap').hashCode() } @@ -143,16 +145,19 @@ class RoleEditor extends Component { { vm .filter((_, k) => k !== 'Uncategorized') - .map((c, name) => c.get('position')) + .map((c, name, arr) => ) .toArray() } diff --git a/UI/src/components/role-picker/actions.js b/UI/src/components/role-picker/actions.js index 81c6dd1..2b59857 100644 --- a/UI/src/components/role-picker/actions.js +++ b/UI/src/components/role-picker/actions.js @@ -19,6 +19,7 @@ export const setup = id => async dispatch => { export const getViewMap = server => { const roles = server.get('roles') const categories = server.get('categories') + const categoriesIds = server.get('categories').keySeq() const allRoles = server.get('roles').filter(v => v.get('safe')).map(r => r.get('id')).toSet() const accountedRoles = categories.map(c => c.get('roles')).toSet().flatten() @@ -31,7 +32,17 @@ export const getViewMap = server => { hidden: true, type: 'multi', name: 'Uncategorized' - })).map(c => { + })) + .map( + (cat, idx) => + cat.set( + 'position', + cat.get('position', categoriesIds.findIndex(v => v === idx) + ) + ) + ) + // .sortBy(cat => cat.get('position')) + .map(c => { const roles = c.get('roles') // fill in roles_map .map(r => diff --git a/UI/src/components/role-picker/index.js b/UI/src/components/role-picker/index.js index 302e1e3..ab009ff 100644 --- a/UI/src/components/role-picker/index.js +++ b/UI/src/components/role-picker/index.js @@ -134,7 +134,7 @@ class RolePicker extends Component {
{ - vm.map((c, name) => dispatch(Actions.updateRoles(roles))} />).toArray() + vm.sortBy(v => v.get('position')).map((c, name) => dispatch(Actions.updateRoles(roles))} />).toArray() }
diff --git a/UI/src/index.css b/UI/src/index.css index 4b1a34f..8cbb949 100644 --- a/UI/src/index.css +++ b/UI/src/index.css @@ -62,4 +62,8 @@ h1,h2,h3,h4,h5,h6 { .fade { opacity: 0; +} + +.yeet { + display: none; } \ No newline at end of file