Skip to content

Commit

Permalink
Merge pull request #157 from advaita-krishna-das/#148_proposals_reord…
Browse files Browse the repository at this point in the history
…ering

#148 proposals reordering
  • Loading branch information
akdasa committed Jan 31, 2018
2 parents a0e241b + d3cfa17 commit 455c5cd
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 7 deletions.
3 changes: 2 additions & 1 deletion gem/web/blueprints/sessions/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def _extend(self, model):

if model:
d = proposals.find({"_id": {"$in": model.get("proposals", [])}})
result_proposals = {str(key["_id"]): key for key in d}
rp = {str(key["_id"]): key for key in d}
result_proposals = list(map(lambda x: rp.get(str(x), None), model.get("proposals", [])))

role_docs = roles.all()
result_roles = map(lambda x: x["name"], role_docs)
Expand Down
20 changes: 15 additions & 5 deletions gem/web/blueprints/sessions/sessions_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function createSessionsController() {
}

me.refreshProposalsList = function() {
var ids = Object.keys(me.proposals);
var ids = me.proposals.map(function (i) { return i["_id"] });

var html = me.proposalsTemplate({
proposals: controller.proposals,
empty: "No proposals added to session",
Expand All @@ -35,10 +36,21 @@ function createSessionsController() {
controller.removeProposal(key)
})
$('[data-toggle="tooltip"]').tooltip()

$("#proposals").sortable({
cursor: "move",
stop: function () {
var sids = $(".list-group-item").map(function (x) {
return $(this).data("id")
}).toArray()
console.log(sids)
$("#proposals-ids").val(sids)
}
})
}

me.appendProposalToSession = function(proposalKey, proposalTitle) {
me.proposals[proposalKey] = {title: proposalTitle, "_id": proposalKey}
me.proposals.push({title: proposalTitle, "_id": proposalKey})
me.refreshProposalsList()
me.closeAddProposalDialog()
}
Expand All @@ -65,9 +77,7 @@ function createSessionsController() {
}

me.removeProposal = function(proposalKey) {
if (proposalKey in me.proposals) {
delete me.proposals[proposalKey]
}
me.proposals = me.proposals.filter(function (i) { return i["_id"] != proposalKey })
me.refreshProposalsList()
}

Expand Down
3 changes: 2 additions & 1 deletion gem/web/blueprints/sessions/sessions_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<label for="proposals" class="col-sm-2 control-label">Proposals</label>
<div class="col-sm-10">
<div id="proposals" class="list-group"></div>
<p class="help-block">Hold and drag to reorder.</p>

<a id="proposal-add" class="form-control btn btn-primary">Add proposal</a>
<input id="proposals-ids" name="proposals" type="hidden">
Expand Down Expand Up @@ -159,7 +160,7 @@ <h4 class="modal-title">Add proposal to session</h4>
<script id="entry-template" type="text/x-handlebars-template">
{% raw %}
{{#each proposals}}
<a href="#" class="list-group-item" data-key="{{key}}">
<a href="#" class="list-group-item" data-key="{{key}}" data-id="{{_id}}">
{{title}}
{{#if ../showDelete }}
<span class="pull-right glyphicon glyphicon-trash session-remove-proposal"
Expand Down
Loading

0 comments on commit 455c5cd

Please sign in to comment.