Skip to content

Commit

Permalink
Fix #2660 implemented first version of save functionalities for dashb…
Browse files Browse the repository at this point in the history
…oard (#2832)
  • Loading branch information
offtherailz authored Apr 23, 2018
1 parent fb3b1f1 commit f595cde
Show file tree
Hide file tree
Showing 43 changed files with 2,411 additions and 51 deletions.
90 changes: 80 additions & 10 deletions web/client/actions/__tests__/dashboard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,86 @@ var expect = require('expect');

const {
setEditing, SET_EDITING,
setEditorAvailable, SET_EDITOR_AVAILABLE
setEditorAvailable, SET_EDITOR_AVAILABLE,
triggerShowConnections, SHOW_CONNECTIONS,
triggerSave, TRIGGER_SAVE_MODAL,
saveDashboard, SAVE_DASHBOARD,
dashboardSaveError, SAVE_ERROR,
dashboardSaved, DASHBOARD_SAVED,
loadDashboard, LOAD_DASHBOARD,
dashboardLoaded, DASHBOARD_LOADED,
dashboardLoading, DASHBOARD_LOADING
} = require('../dashboard');

it('setEditing', () => {
const retval = setEditing();
expect(retval).toExist();
expect(retval.type).toBe(SET_EDITING);
});
it('setEditorAvailable', () => {
const retval = setEditorAvailable();
expect(retval).toExist();
expect(retval.type).toBe(SET_EDITOR_AVAILABLE);
describe('Test correctness of the dashboard actions', () => {
it('setEditing', () => {
const retval = setEditing();
expect(retval).toExist();
expect(retval.type).toBe(SET_EDITING);
});
it('setEditorAvailable', () => {
const retval = setEditorAvailable();
expect(retval).toExist();
expect(retval.type).toBe(SET_EDITOR_AVAILABLE);
});
it('triggerShowConnections', () => {
const retval = triggerShowConnections(true);
expect(retval).toExist();
expect(retval.type).toBe(SHOW_CONNECTIONS);
expect(retval.show).toBe(true);
});
it('triggerShowConnections', () => {
const retval = triggerShowConnections();
expect(retval).toExist();
expect(retval.type).toBe(SHOW_CONNECTIONS);
});
it('triggerSave', () => {
const retval = triggerSave();
expect(retval).toExist();
expect(retval.type).toBe(TRIGGER_SAVE_MODAL);
});
it('saveDashboard', () => {
const retval = saveDashboard({TEST: "TEST"});
expect(retval).toExist();
expect(retval.type).toBe(SAVE_DASHBOARD);
expect(retval.resource.TEST).toBe("TEST");
});
it('dashboardSaveError', () => {
const retval = dashboardSaveError("ERROR");
expect(retval).toExist();
expect(retval.type).toBe(SAVE_ERROR);
expect(retval.error).toBe("ERROR");
});
it('dashboardSaved', () => {
const retval = dashboardSaved();
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_SAVED);
});
it('loadDashboard', () => {
const retval = loadDashboard(1);
expect(retval).toExist();
expect(retval.type).toBe(LOAD_DASHBOARD);
expect(retval.id).toBe(1);
});
it('dashboardLoaded', () => {
const retval = dashboardLoaded("RES", "DATA");
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_LOADED);
expect(retval.resource).toBe("RES");
expect(retval.data).toBe("DATA");
});
it('dashboardLoading default', () => {
const retval = dashboardLoading(false);
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_LOADING);
expect(retval.name).toBe("loading");
expect(retval.value).toBe(false);
});
it('dashboardLoading', () => {
const retval = dashboardLoading(true, "saving");
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_LOADING);
expect(retval.name).toBe("saving");
expect(retval.value).toBe(true);
});
});
34 changes: 33 additions & 1 deletion web/client/actions/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
const SET_EDITOR_AVAILABLE = "DASHBOARD:SET_AVAILABLE";
const SET_EDITING = "DASHBOARD:SET_EDITING";
const SHOW_CONNECTIONS = "DASHBOARD:SHOW_CONNECTIONS";
const TRIGGER_SAVE_MODAL = "DASHBOARD:TRIGGER_SAVE_MODAL";

const SAVE_DASHBOARD = "DASHBOARD:SAVE_DASHBOARD";
const SAVE_ERROR = "DASHBOARD:SAVE_ERROR";
const DASHBOARD_SAVED = "DASHBOARD:DASHBOARD_SAVED";

const LOAD_DASHBOARD = "DASHBOARD:LOAD_DASHBOARD";
const DASHBOARD_LOADED = "DASHBOARD:DASHBOARD_LOADED";
const DASHBOARD_LOADING = "DASHBOARD:DASHBOARD_LOADING";

module.exports = {
SET_EDITING,
setEditing: (editing) => ({type: SET_EDITING, editing }),
SET_EDITOR_AVAILABLE,
setEditorAvailable: available => ({type: SET_EDITOR_AVAILABLE, available}),
SHOW_CONNECTIONS,
triggerShowConnections: show => ({ type: SHOW_CONNECTIONS, show})
triggerShowConnections: show => ({ type: SHOW_CONNECTIONS, show}),
TRIGGER_SAVE_MODAL,
triggerSave: show => ({ type: TRIGGER_SAVE_MODAL, show}),
SAVE_DASHBOARD,
saveDashboard: resource => ({ type: SAVE_DASHBOARD, resource}),
SAVE_ERROR,
dashboardSaveError: error => ({type: SAVE_ERROR, error}),
DASHBOARD_SAVED,
dashboardSaved: id => ({type: DASHBOARD_SAVED, id}),
LOAD_DASHBOARD,
loadDashboard: id => ({ type: LOAD_DASHBOARD, id}),
DASHBOARD_LOADED,
dashboardLoaded: (resource, data) => ({ type: DASHBOARD_LOADED, resource, data}),
DASHBOARD_LOADING,
/**
* @param {boolean} value the value of the flag
* @param {string} [name] the name of the flag to set. loading is anyway always triggered
*/
dashboardLoading: (value, name = "loading") => ({
type: DASHBOARD_LOADING,
name,
value
})
};
25 changes: 25 additions & 0 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ const Api = {
"resources/resource/" + resourceId,
this.addBaseUrl(parseOptions(options))).then(function(response) {return response.data; });
},
getShortResource: function(resourceId, options) {
return axios.get(
"extjs/resource/" + resourceId,
this.addBaseUrl(parseOptions(options))).then(function(response) { return response.data; });
},
getResourcesByCategory: function(category, query, options) {
const q = query || "*";
const url = "extjs/search/category/" + category + "/*" + q + "*/thumbnail,details,featured"; // comma-separated list of wanted attributes
Expand Down Expand Up @@ -142,6 +147,26 @@ const Api = {
}
}, options)));
},
getResourceAttributes: function(resourceId, options = {}) {
return axios.get(
"resources/resource/" + resourceId + "/attributes",
this.addBaseUrl({
headers: {
'Accept': "application/json"
},
...options
})).then(({ data } = {}) => data)
.then(data => _.castArray(_.get(data, "AttributeList.Attribute")))
.then(attributes => (attributes && attributes[0] && attributes[0] !== "") ? attributes : []);
},
/**
* same of getPermissions but clean data properly and returns only the array of rules.
*/
getResourcePermissions: function(resourceId, options) {
return Api.getPermissions(resourceId, options)
.then(rl => _.castArray(_.get(rl, 'SecurityRuleList.SecurityRule')))
.then(rules => (rules && rules[0] && rules[0] !== "") ? rules : []);
},
putResourceMetadata: function(resourceId, newName, newDescription, options) {
return axios.put(
"resources/resource/" + resourceId,
Expand Down
85 changes: 85 additions & 0 deletions web/client/components/dashboard/forms/Metadata.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const React = require('react');
const PropTypes = require('prop-types');
const {FormControl: BFormControl, FormGroup, ControlLabel} = require('react-bootstrap');
const FormControl = require('../../misc/enhancers/localizedProps')('placeholder')(BFormControl);

/**
* A DropDown menu for user details:
*/
class Metadata extends React.Component {
static propTypes = {
resource: PropTypes.object,
// CALLBACKS
onChange: PropTypes.func,

// I18N
nameFieldText: PropTypes.node,
descriptionFieldText: PropTypes.node,
namePlaceholderText: PropTypes.string,
descriptionPlaceholderText: PropTypes.string
};

static defaultProps = {
// CALLBACKS
onChange: () => {},
resource: {},
// I18N
nameFieldText: "Name",
descriptionFieldText: "Description",
namePlaceholderText: "Map Name",
descriptionPlaceholderText: "Map Description"
};

render() {
return (<form ref="metadataForm" onSubmit={this.handleSubmit}>
<FormGroup>
<ControlLabel>{this.props.nameFieldText}</ControlLabel>
<FormControl
key="mapName"
type="text"
onChange={this.changeName}
disabled={this.props.resource.saving}
placeholder={this.props.namePlaceholderText}
defaultValue={this.props.resource ? this.props.resource.name : ""}
value={this.props.resource && this.props.resource.metadata && this.props.resource.metadata.name || ""}/>
</FormGroup>
<FormGroup>
<ControlLabel>{this.props.descriptionFieldText}</ControlLabel>
<FormControl
key="mapDescription"
type="text"
onChange={this.changeDescription}
disabled={this.props.resource.saving}
placeholder={this.props.descriptionPlaceholderText}
defaultValue={this.props.resource ? this.props.resource.description : ""}
value={this.props.resource && this.props.resource.metadata && this.props.resource.metadata.description || ""}/>
</FormGroup>
</form>);
}

changeName = (e) => {
this.props.onChange('metadata.name', e.target.value);
};

changeDescription = (e) => {
this.props.onChange('metadata.description', e.target.value);
};
}


module.exports = Metadata;
Loading

0 comments on commit f595cde

Please sign in to comment.