Display list of tags

This commit is contained in:
James Allen 2014-06-11 16:32:56 +01:00
parent 1eaba59df0
commit 067d343928
3 changed files with 75 additions and 39 deletions

View file

@ -211,16 +211,11 @@ _buildListViewModel = (projects, collabertions, readOnlyProjects, tags, tagsGrou
for project in readOnlyProjects
project.accessLevel = "readOnly"
projects = projects.concat(collabertions).concat(readOnlyProjects)
projects = projects.map (project)->
project.tags = tagsGroupedByProject[project._id] || []
return project
tags = _.sortBy tags, (tag)->
-tag.project_ids.length
return {
title:'Your Projects'
priority_title: true
projects: JSON.stringify(projects)
tags:tags
tags: JSON.stringify(tags)
projectTabActive: true
}

View file

@ -7,7 +7,10 @@ block content
#projectList
script(type="text/javascript").
window.data = { projects: !{projects} };
window.data = {
projects: !{projects},
tags: !{tags}
};
script(type="text/x-handlebars", data-template-name="projects")
- if (projects.length > 0)
@ -46,6 +49,24 @@ block content
a(href="/learn") help guides
| .
script(type="text/x-handlebars", data-template-name="tags")
ul.list-unstyled.folders-menu.js-folders-menu
li
a.menu-indent(href="#") All projects
li
a.menu-indent(href="#") Your projects
li
a.menu-indent(href="#") Shared with you
li
h2 Folders
{{#each itemController="tag"}}
li
a.menu-indent(href="#")
i.icon.fa.fa-folder-o
| {{name}}
span.small ({{projectCount}})
{{/each}}
script(type="text/x-handlebars", data-template-name="application")
.content.content-alt
.container
@ -77,30 +98,7 @@ block content
li
a.menu-indent(href="/templates") View All »
.row-spaced
ul.list-unstyled.folders-menu.js-folders-menu
li
a.menu-indent(href="#") All projects
li
a.menu-indent(href="#") Your projects
li
a.menu-indent(href="#") Shared with you
li
h2 Folders
li
a.menu-indent(href="#")
i.icon.fa.fa-folder-o
| PhD work
span.small (5)
li
a.menu-indent(href="#")
i.icon.fa.fa-folder-o
| Notes
span.small (2)
li
a.menu-indent(href="#")
i.icon.fa.fa-folder-o
| Papers
span.small (1)
{{ render "tags" }}
.row-spaced-small
ul.list-unstyled.folders-menu

View file

@ -3,17 +3,38 @@ window.ProjectList = Ember.Application.create {
}
ProjectList.ApplicationRoute = Ember.Route.extend {
model: () ->
return @store.find("project")
setupController: () ->
@controllerFor('projects').set('model', @store.find("project"))
# TODO: Figure out how to get the findAll method
for project in window.data.projects
project = @store.createRecord('project', {
id: project._id
name: project.name
lastUpdated: project.lastUpdated
})
for tag in window.data.tags
tagObject = @store.createRecord('tag', {
id: tag._id
name: tag.name
})
for project_id in tag.project_ids
project = @store.getById('project', project_id)
if project?
tagObject.get("projects").pushObject(project)
@controllerFor('projects').set('model', @store.all("project"))
@controllerFor('tags').set('model', @store.all("tag"))
}
ProjectList.Tag = DS.Model.extend {
name: DS.attr("string")
projects: DS.hasMany("project")
}
ProjectList.Project = DS.Model.extend {
name: DS.attr("string")
ownerName: DS.attr("string")
lastUpdated: DS.attr("date")
tags: DS.hasMany("tag")
}
ProjectList.ProjectsController = Ember.ArrayController.extend {
@ -32,14 +53,36 @@ ProjectList.ProjectController = Ember.ObjectController.extend {
).property("lastUpdated")
}
ProjectList.TagsController = Ember.ArrayController.extend {
sortProperties: ["name"]
sortAscending: true
}
ProjectList.TagController = Ember.ObjectController.extend {
projectCount: (() ->
@get("model").get("projects.length")
).property("projects.length")
}
ProjectList.ApplicationAdapter = DS.Adapter.extend {
findAll: (store, type, sinceToken) ->
return new Ember.RSVP.Promise (resolve, reject) ->
resolve(
window.data.projects.map (project) ->
console.log "Grabbing", type
if type == ProjectList.Project
return new Ember.RSVP.Promise (resolve, reject) ->
Ember.run null, resolve, window.data.projects.map (project) ->
id: project._id
name: project.name
lastUpdated: project.lastUpdated
)
tag_ids: ["53230518ee024fe3e88ca988"]
else if type == ProjectList.Tag
return new Ember.RSVP.Promise (resolve, reject) ->
Ember.run null, resolve, window.data.tags.map (tag) ->
{
id: tag._id
name: tag.name
project_ids: tag.project_ids
}
}