Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2664 Implemented browsing functionality for dashboards #2854

Merged
merged 13 commits into from
May 3, 2018
Merged
6 changes: 6 additions & 0 deletions web/client/actions/__tests__/dashboard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
dashboardSaveError, SAVE_ERROR,
dashboardSaved, DASHBOARD_SAVED,
loadDashboard, LOAD_DASHBOARD,
resetDashboard, DASHBOARD_RESET,
dashboardLoaded, DASHBOARD_LOADED,
dashboardLoading, DASHBOARD_LOADING
} = require('../dashboard');
Expand Down Expand Up @@ -70,6 +71,11 @@ describe('Test correctness of the dashboard actions', () => {
expect(retval.type).toBe(LOAD_DASHBOARD);
expect(retval.id).toBe(1);
});
it('resetDashboard', () => {
const retval = resetDashboard();
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_RESET);
});
it('dashboardLoaded', () => {
const retval = dashboardLoaded("RES", "DATA");
expect(retval).toExist();
Expand Down
74 changes: 74 additions & 0 deletions web/client/actions/__tests__/dashboards-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2018, 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.
*/
var expect = require('expect');
const {
setDashboardsAvailable, SET_DASHBOARDS_AVAILABLE,
searchDashboards, SEARCH_DASHBOARDS,
dashboardsLoading, LOADING,
dashboardListLoaded, DASHBOARDS_LIST_LOADED,
deleteDashboard, DELETE_DASHBOARD,
dashboardDeleted, DASHBOARD_DELETED,
reloadDashboards, RELOAD


} = require('../dashboards');
describe('dashboards (browse) actions', () => {
it('setDashboardsAvailable', () => {
const retval = setDashboardsAvailable(true);
expect(retval).toExist();
expect(retval.type).toBe(SET_DASHBOARDS_AVAILABLE);
expect(retval.available).toBe(true);

});
it('searchDashboards', () => {
const retval = searchDashboards();
expect(retval).toExist();
expect(retval.type).toBe(SEARCH_DASHBOARDS);
});
it('dashboardLoading', () => {
const retval = dashboardsLoading(true, "test");
expect(retval).toExist();
expect(retval.type).toBe(LOADING);
expect(retval.value).toBe(true);
expect(retval.name).toBe("test");
});
it('dashboardListLoaded', () => {
const retval = dashboardListLoaded({
results: [{id: 1}],
success: true,
totalCount: 1
}, {
searchText: "test",
options: "someOptions"
});
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARDS_LIST_LOADED);
expect(retval.results[0].id).toBe(1);
expect(retval.totalCount).toBe(1);
expect(retval.success).toBe(true);
expect(retval.searchText).toBe("test");
expect(retval.options).toBe("someOptions");
});
it('deleteDashboard', () => {
const retval = deleteDashboard(1);
expect(retval).toExist();
expect(retval.type).toBe(DELETE_DASHBOARD);
expect(retval.id).toBe(1);
});
it('dashboardDeleted', () => {
const retval = dashboardDeleted();
expect(retval).toExist();
expect(retval.type).toBe(DASHBOARD_DELETED);
});
it('reloadDashboards', () => {
const retval = reloadDashboards();
expect(retval).toExist();
expect(retval.type).toBe(RELOAD);
});

});
3 changes: 3 additions & 0 deletions web/client/actions/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SAVE_ERROR = "DASHBOARD:SAVE_ERROR";
const DASHBOARD_SAVED = "DASHBOARD:DASHBOARD_SAVED";

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

Expand All @@ -29,6 +30,8 @@ module.exports = {
LOAD_DASHBOARD,
loadDashboard: id => ({ type: LOAD_DASHBOARD, id}),
DASHBOARD_LOADED,
DASHBOARD_RESET,
resetDashboard: () => ({ type: DASHBOARD_RESET}),
dashboardLoaded: (resource, data) => ({ type: DASHBOARD_LOADED, resource, data}),
DASHBOARD_LOADING,
/**
Expand Down
40 changes: 40 additions & 0 deletions web/client/actions/dashboards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2018, 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 SET_DASHBOARDS_AVAILABLE = "DASHBOARDS:SET_DASHBOARDS_AVAILABLE";
const SEARCH_DASHBOARDS = "DASHBOARDS:SEARCH_DASHBOARDS";
const DASHBOARDS_LIST_LOADED = "DASHBOARDS:DASHBOARDS_LIST_LOADED";
const DELETE_DASHBOARD = "DASHBOARDS:DELETE_DASHBOARD";
const DASHBOARD_DELETED = "DASHBOARDS:DASHBOARD_DELETED";
const RELOAD = "DASHBOARDS:RELOAD_DASHBOARDS";
const LOADING = "DASHBOARDS:LOADING";

module.exports = {
SET_DASHBOARDS_AVAILABLE,
setDashboardsAvailable: (available) => ({ type: SET_DASHBOARDS_AVAILABLE, available }),
SEARCH_DASHBOARDS,
searchDashboards: (searchText, params) => ({ type: SEARCH_DASHBOARDS, searchText, params }),
LOADING,
/**
* @param {boolean} value the value of the flag
* @param {string} [name] the name of the flag to set. loading is anyway always triggered
*/
dashboardsLoading: (value, name = "loading") => ({
type: LOADING,
name,
value
}),
DASHBOARDS_LIST_LOADED,
dashboardListLoaded: ({ results, success, totalCount }, { searchText, options } = {}) => ({ type: DASHBOARDS_LIST_LOADED, results, success, totalCount, searchText, options }),
DELETE_DASHBOARD,
deleteDashboard: id => ({type: DELETE_DASHBOARD, id}),
DASHBOARD_DELETED,
RELOAD,
reloadDashboards: () => ({ type: RELOAD}),
dashboardDeleted: id => ({type: DASHBOARD_DELETED, id})
};
4 changes: 2 additions & 2 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ const Api = {
},
...options
})).then(({ data } = {}) => data)
.then(data => _.castArray(_.get(data, "AttributeList.Attribute")))
.then(attributes => (attributes && attributes[0] && attributes[0] !== "") ? attributes : []);
.then(data => _.castArray(_.get(data, "AttributeList.Attribute") || []))
.then(attributes => attributes || []);
},
/**
* same of getPermissions but clean data properly and returns only the array of rules.
Expand Down
93 changes: 0 additions & 93 deletions web/client/components/dashboard/modals/Confirm.jsx

This file was deleted.

35 changes: 28 additions & 7 deletions web/client/components/maps/MapCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*/
const PropTypes = require('prop-types');
const React = require('react');
const {get} = require('lodash');
const Message = require('../I18N/Message');
const GridCard = require('../misc/GridCard');
const FitIcon = require('../misc/FitIcon');

const thumbUrl = require('./style/default.jpg');
const assign = require('object-assign');
const ConfirmModal = require('./modals/ConfirmModal');
Expand All @@ -19,14 +22,14 @@ class MapCard extends React.Component {
style: PropTypes.object,
map: PropTypes.object,
detailsSheetActions: PropTypes.object,
mapType: PropTypes.string,
// CALLBACKS
viewerUrl: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
onEdit: PropTypes.func,
onMapDelete: PropTypes.func,
onUpdateAttribute: PropTypes.func,
backgroundOpacityStart: PropTypes.number,
backgroundOpacityEnd: PropTypes.number
backgroundOpacityEnd: PropTypes.number,
tooltips: PropTypes.object
};

static contextTypes = {
Expand All @@ -48,7 +51,14 @@ class MapCard extends React.Component {
onEdit: () => {},
onUpdateAttribute: () => {},
backgroundOpacityStart: 0.7,
backgroundOpacityEnd: 0.3
backgroundOpacityEnd: 0.3,
tooltips: {
deleteResource: "resources.resource.deleteResource",
editResource: "resources.resource.editResource",
addToFeatured: "resources.resource.addToFeatured",
showDetails: "resources.resource.showDetails",
removeFromFeatured: "resources.resource.removeFromFeatured"
}
};

onEdit = (map, openModalProperties) => {
Expand Down Expand Up @@ -87,14 +97,14 @@ class MapCard extends React.Component {
glyph: 'trash',
disabled: this.props.map.deleting,
loading: this.props.map.deleting,
tooltipId: 'manager.deleteMap',
tooltipId: this.props.tooltips.deleteResource,
onClick: evt => {
this.stopPropagate(evt);
this.displayDeleteDialog();
}
},
{
visible: this.props.map.canEdit === true,
visible: this.props.map.canEdit === true && (get(this.props.map, "category.name") !== "DASHBOARD"),
glyph: 'wrench',
disabled: this.props.map.updating,
loading: this.props.map.updating,
Expand All @@ -107,7 +117,7 @@ class MapCard extends React.Component {
{
visible: !!(this.props.map.details && this.props.map.details !== 'NODATA'),
glyph: 'sheet',
tooltipId: 'map.details.show',
tooltipId: this.props.tooltips.showDetails,
onClick: evt => {
this.stopPropagate(evt);
this.onEdit(this.props.map, false);
Expand All @@ -118,7 +128,7 @@ class MapCard extends React.Component {
visible: !!(this.props.map.canEdit === true && this.props.map.featuredEnabled),
glyph: isFeatured ? 'star' : 'star-empty',
bsStyle: isFeatured ? 'success' : 'primary',
tooltipId: isFeatured ? 'maps.removeFromFeaturedMaps' : 'maps.addToFeaturedMaps',
tooltipId: isFeatured ? this.props.tooltips.removeFromFeatured : this.props.tooltips.addToFeatured,
onClick: evt => {
this.stopPropagate(evt);
this.props.onUpdateAttribute(this.props.map.id, 'featured', !isFeatured);
Expand All @@ -131,6 +141,17 @@ class MapCard extends React.Component {
actions={availableAction} onClick={this.onClick}
>
<div className="map-thumb-description">{this.props.map.description}</div>
{this.props.map.icon ?
<div key="icon" style={{
width: "20px",
height: "20px",
margin: "5px 10px",
color: "white",
position: "absolute",
bottom: 0,
left: 0 }} >
<FitIcon glyph={this.props.map.icon} />
</div> : null}
<ConfirmModal ref="deleteMapModal" show={this.state ? this.state.displayDeleteDialog : false} onHide={this.close} onClose={this.close} onConfirm={this.onConfirmDelete} titleText={<Message msgId="manager.deleteMap" />} confirmText={<Message msgId="manager.deleteMap" />} cancelText={<Message msgId="cancel" />} body={<Message msgId="manager.deleteMapMessage" />} />
</GridCard>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('featuredMaps enhancher', () => {
items: [{
id: 2,
name: 'Map',
category: {
id: 1,
name: "MAP"
},
icon: "1-map",
canCopy: true,
canDelete: true,
canEdit: true,
Expand Down
13 changes: 13 additions & 0 deletions web/client/components/maps/enhancers/featuredMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,26 @@ const parseAttributes = (record) => {
const attributesArray = isArray(attributes) && attributes || isObject(attributes) && [attributes];
return attributesArray && attributesArray.reduce((newAttributes, attribute) => ({...newAttributes, [attribute.name]: attribute.value}), {}) || {};
};
const getIcon = record => {
const cat = get(record, "category.name");
switch (cat) {
case "MAP":
return "1-map";
case "DASHBOARD":
return "dashboard";
default:
return undefined;
}
};
/*
* converts record item into a item for MapsGrid
*/
const resultToProps = ({result = {}, permission}) => ({
items: (isArray(result.Resource) && result.Resource || isObject(result.Resource) && [result.Resource] || []).map((record = {}) => ({
id: record.id,
name: record.name,
category: record.category,
icon: getIcon(record),
canCopy: permission,
canDelete: permission,
canEdit: permission,
Expand Down
Loading