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

edit grids and pathways #384

Merged
merged 1 commit into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/grid.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Grid < ActiveRecord::Base
belongs_to :map
has_many :pathways
has_many :pathways, :dependent => :delete_all
validates :name, presence: true, allow_blank: false
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('caac.dashboard.organizers.controller', [
var logger = $log.getInstance('OrganizersDashboardController');
TitleService.set('Organizers Dashboard');

self.comingSoon= function() {
self.comingSoon = function() {
alert('Coming soon!');
};
self.path = OrganizersService.path;
Expand Down
26 changes: 22 additions & 4 deletions client/dashboard/organizers/map/MapController.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,41 @@ angular.module('caac.dashboard.organizers.map.controller', [
// ======

self.editGrid = function(grid) {
alert("Edit" + grid.name);
var name = prompt("Okay! Let's edit '" + grid.name + "'. What should its new name be?");
GridsService.edit(grid, name).then(function(res) {
grid.name = name;
});
};

self.editPathway = function(pathway) {
alert("Edit " + pathway.name);
var name = prompt("Okay! Let's edit '" + pathway.name + "'. What should its new name be?");
PathwaysService.edit(pathway, name).then(function(res) {
pathway.name = name;
});
};


// Delete
// ======

self.deleteGrid = function(grid) {
alert("Delete " + grid.name);
if (confirm("Really delete grid '" + grid.name + "'?")) {
GridsService.delete_(grid).then(function(res) {
var i = self.grids.indexOf(grid);
self.grids.splice(i, 1);
self.selectGrid(self.grids[i-1]);
});
}
};

self.deletePathway = function(pathway) {
alert("Delete " + pathway.name);
if (confirm("Really delete pathway '" + pathway.name + "'?")) {
PathwaysService.delete_(pathway).then(function(res) {
var i = self.currentGrid.pathways.indexOf(pathway);
self.currentGrid.pathways.splice(i, 1);
self.selectPathway(self.currentGrid.pathways[i-1]);
});
}
};


Expand Down
12 changes: 6 additions & 6 deletions client/dashboard/organizers/map/MapView.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ <h1>Organize Your Map</h1>
<div class="pane nav">
<h3>All Grids</h3>
<ul>
<li ng-repeat="grid in grids"
<li ng-repeat="grid in grids | orderBy:'name'"
ng-class="{'selected': currentGrid === grid }"
ng-click="selectGrid(grid)"
>
{{grid.name}}
<span class="delete" ng-click="deleteGrid(grid)">[x]</span>
<span class="edit" ng-click="editGrid(grid)">[/]</span>
<span class="delete" ng-click="deleteGrid(grid)"></span>
<span class="edit" ng-click="editGrid(grid)"></span>
</li>
<li><button ng-click="insertGrid()">Add a Grid</button></li>
</ul>
</div>
<div class="pane nav">
<h3>Pathways in {{currentGrid.name||'...'}}</h3>
<ul>
<li ng-repeat="pathway in currentGrid.pathways"
<li ng-repeat="pathway in currentGrid.pathways | orderBy:'name'"
ng-class="{'selected': currentPathway === pathway}"
ng-click="selectPathway(pathway)"
>
{{pathway.name}}
<span class="delete" ng-click="deletePathway(pathway)">[x]</span>
<span class="edit" ng-click="editPathway(pathway)">[/]</span>
<span class="delete" ng-click="deletePathway(pathway)"></span>
<span class="edit" ng-click="editPathway(pathway)"></span>
</li>
<li><button ng-click="insertPathway(currentGrid)">Add a Pathway</button></li>
</ul>
Expand Down
10 changes: 6 additions & 4 deletions client/dashboard/organizers/map/_MapStyle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
float: right;
height: 16px;
width: 16px;
text-align: center;
&:hover {
background: red;
}
background-repeat: no-repeat;
background-size: contain;
&.edit { background-image: url("/shared/assets/edit.svg"); }
&.delete { background-image: url("/shared/assets/delete.svg"); }
&:hover { background-color: #ffff99; }
}

&:hover span {
display: block;
}
Expand Down
12 changes: 12 additions & 0 deletions client/grids/GridsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ angular.module('caac.grids.service', [
return $http.post('/api/v1/grids.json', {name: name, organizer_id: organizer_id});
};

var edit = function(grid, newName) {
logger.info('attempting to rename grid "' + grid.name + '" to "' + newName + '"');
return $http.put('/api/v1/grids/' + grid.id + '.json', {name: newName});
};

var delete_ = function(grid) {
logger.info('attempting to remove grid "' + grid.name + '"');
return $http.delete('/api/v1/grids/' + grid.id + '.json');
};

return {
insert: insert,
edit: edit,
delete_: delete_,
selectAll: selectAll
};
}
Expand Down
14 changes: 13 additions & 1 deletion client/pathways/PathwaysService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ angular.module('caac.pathways.service', [
return $http.post('/api/v1/pathways.json', {name: name, grid_id: grid.id});
};

var edit = function(pathway, newName) {
logger.info('attempting to rename pathway "' + pathway.name + '" to "' + newName + '"');
return $http.put('/api/v1/pathways/' + pathway.id + '.json', {name: newName});
};

var delete_ = function(pathway) {
logger.info('attempting to remove pathway "' + pathway.name + '"');
return $http.delete('/api/v1/pathways/' + pathway.id + '.json');
};

return {
insert: insert
insert: insert,
delete_: delete_,
edit: edit
};
}
]);
1 change: 1 addition & 0 deletions client/shared/assets/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/shared/assets/edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.