Skip to content

Commit

Permalink
feat(sidebar.box): add edit icon
Browse files Browse the repository at this point in the history
It is now possible to edit your boxes from the details sidebar. If you are logged in and viewing one
of your boxes a pencil icon is shown.

#258
  • Loading branch information
mpfeil committed Feb 16, 2018
1 parent 2561ce1 commit aa6a94f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions app/scripts/controllers/sidebar.boxdetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.module('openSenseMapApp')
.controller('SidebarBoxDetailsController', SidebarBoxDetailsController);

SidebarBoxDetailsController.$inject = ['$scope', '$stateParams', 'moment', '$timeout', 'Box', 'OpenSenseMapAPI', 'osemMapData', 'Sidebar'];
SidebarBoxDetailsController.$inject = ['$scope', '$state', '$stateParams', 'moment', '$timeout', 'Box', 'OpenSenseMapAPI', 'osemMapData', 'Sidebar', 'LocalStorageService'];

function SidebarBoxDetailsController ($scope, $stateParams, moment, $timeout, Box, OpenSenseMapAPI, osemMapData, Sidebar) {
function SidebarBoxDetailsController ($scope, $state, $stateParams, moment, $timeout, Box, OpenSenseMapAPI, osemMapData, Sidebar, LocalStorageService) {
var vm = this;
vm.box = {};
vm.selectedSensor = null;
Expand All @@ -16,20 +16,27 @@
vm.selectSensor = selectSensor;
vm.resetFilter = resetFilter;
vm.performFilter = performFilter;
vm.getTimeAgo = getTimeAgo;

activate();

////

function activate () {
console.log("Activate Sidebar", moment);
OpenSenseMapAPI.getBox($stateParams.id)
.then(function (response) {
vm.box = new Box(response);
Sidebar.setTitle(vm.box.name);
Sidebar.addAction({href: vm.box.getArchiveLink(), target: '_blank', icon: 'fa-archive', hideOnMinimized: true});
Sidebar.addAction({handler: focusSelectedBox, icon: 'fa-thumb-tack', hideOnMinimized: false});

var account = LocalStorageService.getValue('osem.account');
if (account) {
var boxes = JSON.parse(account).boxes;
if (boxes.indexOf($stateParams.id) > -1) {
Sidebar.addAction({handler: editBox, icon: 'fa-pencil', hideOnMinimized: true});
}
}

focusSelectedBox();
if (vm.box.exposure === 'mobile') getBoxTrajectory();
})
Expand All @@ -56,6 +63,10 @@
})
}

function editBox () {
$state.go('account.edit.general', { id: vm.box._id , box: vm.box });
}

// focus current location of a box or its trajectory, if optional
// `trajectory` GeoJSON linestring is provided
function focusSelectedBox (trajectory) {
Expand Down

0 comments on commit aa6a94f

Please sign in to comment.