new route controller page system
parent
408fc1b8e3
commit
ad6b7fcf1d
|
@ -46,23 +46,23 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
|||
},
|
||||
title: "PROJECT.WELCOME",
|
||||
resolve: {
|
||||
loader: tgLoaderProvider.add(true),
|
||||
pageParams: -> {
|
||||
}
|
||||
loader: tgLoaderProvider.add(true)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
$routeProvider.when("/projects/",
|
||||
{
|
||||
templateUrl: "projects/projects-page.html",
|
||||
templateUrl: "projects/listing/projects-listing.html",
|
||||
access: {
|
||||
requiresLogin: true
|
||||
},
|
||||
title: "PROJECT.SECTION_PROJECTS",
|
||||
resolve: {
|
||||
loader: tgLoaderProvider.add(true)
|
||||
}
|
||||
},
|
||||
controller: "ProjectsListing",
|
||||
controllerAs: "vm"
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -175,14 +175,14 @@ configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEven
|
|||
# User profile
|
||||
$routeProvider.when("/profile",
|
||||
{
|
||||
templateUrl: "profile/profile-page.html",
|
||||
templateUrl: "profile/profile.html",
|
||||
resolve: {
|
||||
loader: tgLoaderProvider.add(true)
|
||||
},
|
||||
access: {
|
||||
requiresLogin: true
|
||||
}
|
||||
controller: "ProfilePage"
|
||||
controller: "Profile"
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -9,4 +9,4 @@ class ProfilePageController extends taiga.Controller
|
|||
|
||||
@appTitle.set(user.username)
|
||||
|
||||
angular.module("taigaProfile").controller("ProfilePage", ProfilePageController)
|
||||
angular.module("taigaProfile").controller("Profile", ProfilePageController)
|
|
@ -1,23 +1,33 @@
|
|||
describe "PageController", ->
|
||||
describe "ProfileController", ->
|
||||
pageCtrl = null
|
||||
provide = null
|
||||
controller = null
|
||||
mocks = {}
|
||||
|
||||
_mockAuth = () ->
|
||||
mocks.authService = {
|
||||
getUser: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgAuth", mocks.authService
|
||||
projects = Immutable.fromJS([
|
||||
{id: 1},
|
||||
{id: 2},
|
||||
{id: 3}
|
||||
])
|
||||
|
||||
_mockAppTitle = () ->
|
||||
stub = sinon.stub()
|
||||
|
||||
mocks.appTitle = {
|
||||
set: sinon.spy()
|
||||
set: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$appTitle", mocks.appTitle
|
||||
|
||||
_mockAuth = () ->
|
||||
stub = sinon.stub()
|
||||
|
||||
mocks.auth = {
|
||||
getUser: sinon.stub()
|
||||
}
|
||||
|
||||
provide.value "$tgAuth", mocks.auth
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
|
@ -34,14 +44,14 @@ describe "PageController", ->
|
|||
inject ($controller) ->
|
||||
controller = $controller
|
||||
|
||||
it "set the username as title", () ->
|
||||
it "define projects", () ->
|
||||
user = {
|
||||
username: 'UserName'
|
||||
username: "UserName"
|
||||
}
|
||||
|
||||
mocks.authService.getUser.returns(user)
|
||||
mocks.auth.getUser.returns(user)
|
||||
|
||||
pageCtrl = controller "ProfilePage",
|
||||
ctrl = controller "Profile",
|
||||
$scope: {}
|
||||
|
||||
expect(mocks.appTitle.set.withArgs(user.username)).have.been.calledOnce
|
||||
expect(mocks.appTitle.set.withArgs(user.username)).to.be.calledOnce
|
|
@ -0,0 +1,12 @@
|
|||
class ProjectsListingController
|
||||
@.$inject = [
|
||||
"tgProjectsService"
|
||||
]
|
||||
|
||||
constructor: (@projectsService) ->
|
||||
taiga.defineImmutableProperty(@, "projects", () => @projectsService.currentUserProjects.get("all"))
|
||||
|
||||
newProject: ->
|
||||
@projectsService.newProject()
|
||||
|
||||
angular.module("taigaProjects").controller("ProjectsListing", ProjectsListingController)
|
|
@ -0,0 +1,54 @@
|
|||
describe "ProjectsListingController", ->
|
||||
pageCtrl = null
|
||||
provide = null
|
||||
controller = null
|
||||
mocks = {}
|
||||
|
||||
projects = Immutable.fromJS([
|
||||
{id: 1},
|
||||
{id: 2},
|
||||
{id: 3}
|
||||
])
|
||||
|
||||
_mockProjectsService = () ->
|
||||
stub = sinon.stub()
|
||||
|
||||
mocks.projectsService = {
|
||||
currentUserProjects: {
|
||||
get: stub
|
||||
},
|
||||
newProject: sinon.stub()
|
||||
}
|
||||
|
||||
stub.withArgs("all").returns(projects)
|
||||
|
||||
provide.value "tgProjectsService", mocks.projectsService
|
||||
|
||||
_mocks = () ->
|
||||
module ($provide) ->
|
||||
provide = $provide
|
||||
_mockProjectsService()
|
||||
|
||||
return null
|
||||
|
||||
beforeEach ->
|
||||
module "taigaProjects"
|
||||
|
||||
_mocks()
|
||||
|
||||
inject ($controller) ->
|
||||
controller = $controller
|
||||
|
||||
it "define projects", () ->
|
||||
pageCtrl = controller "ProjectsListing",
|
||||
$scope: {}
|
||||
|
||||
expect(pageCtrl.projects).to.be.equal(projects)
|
||||
|
||||
it "new project", () ->
|
||||
pageCtrl = controller "ProjectsListing",
|
||||
$scope: {}
|
||||
|
||||
pageCtrl.newProject()
|
||||
|
||||
expect(mocks.projectsService.newProject).to.be.calledOnce;
|
|
@ -1,10 +1,8 @@
|
|||
ProjectsListingDirective = (projectsService) ->
|
||||
SortProjectsDirective = (projectsService) ->
|
||||
link = (scope, el, attrs, ctrl) ->
|
||||
scope.vm = {}
|
||||
itemEl = null
|
||||
tdom = el.find(".js-sortable")
|
||||
|
||||
tdom.sortable({
|
||||
el.sortable({
|
||||
dropOnEmpty: true
|
||||
revert: 200
|
||||
axis: "y"
|
||||
|
@ -12,31 +10,29 @@ ProjectsListingDirective = (projectsService) ->
|
|||
placeholder: 'placeholder'
|
||||
})
|
||||
|
||||
tdom.on "sortstop", (event, ui) ->
|
||||
el.on "sortstop", (event, ui) ->
|
||||
itemEl = ui.item
|
||||
project = itemEl.scope().project
|
||||
index = itemEl.index()
|
||||
|
||||
sorted_project_ids = _.map(scope.vm.projects.toArray(), (p) -> p.id)
|
||||
sorted_project_ids = _.map(scope.projects.toJS(), (p) -> p.id)
|
||||
sorted_project_ids = _.without(sorted_project_ids, project.id)
|
||||
sorted_project_ids.splice(index, 0, project.get('id'))
|
||||
|
||||
sortData = []
|
||||
|
||||
for value, index in sorted_project_ids
|
||||
sortData.push({"project_id": value, "order":index})
|
||||
|
||||
projectsService.bulkUpdateProjectsOrder(sortData)
|
||||
|
||||
taiga.defineImmutableProperty(scope.vm, "projects", () -> projectsService.currentUserProjects.get("all"))
|
||||
|
||||
scope.vm.newProject = ->
|
||||
projectsService.newProject()
|
||||
|
||||
directive = {
|
||||
templateUrl: "projects/listing/projects-listing.html"
|
||||
scope: {}
|
||||
scope: {
|
||||
projects: "=tgSortProjects"
|
||||
},
|
||||
link: link
|
||||
}
|
||||
|
||||
return directive
|
||||
|
||||
angular.module("taigaProjects").directive("tgProjectsListing", ["tgProjectsService", ProjectsListingDirective])
|
||||
angular.module("taigaProjects").directive("tgSortProjects", ["tgProjectsService", SortProjectsDirective])
|
||||
|
|
|
@ -10,7 +10,7 @@ div.project-list-wrapper.centered
|
|||
|
||||
section.project-list-section
|
||||
div.project-list
|
||||
ul.js-sortable
|
||||
ul(tg-sort-projects="vm.projects")
|
||||
li.project-list-single(tg-bind-scope, tg-repeat="project in vm.projects")
|
||||
div.project-list-single-left
|
||||
div.project-list-single-title
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
div(tg-project)
|
|
@ -1,8 +0,0 @@
|
|||
ProjectDirective = () ->
|
||||
return {
|
||||
templateUrl: "projects/project/project.html",
|
||||
controllerAs: "vm",
|
||||
controller: "Project"
|
||||
}
|
||||
|
||||
angular.module("taigaProjects").directive("tgProject", ProjectDirective)
|
|
@ -13,7 +13,7 @@ div.wrapper
|
|||
section.timeline
|
||||
div(tg-user-timeline)
|
||||
section.involved-data
|
||||
h2.title Team
|
||||
h2.title {{"PROJECT.SECTION.TEAM" | translate}}
|
||||
ul.involved-team
|
||||
a(href="", title="{{::member.get('full_name')}}", tg-repeat="member in ::vm.project.get('memberships')")
|
||||
img(ng-src="{{::member.get('photo')}}", alt="{{::member.get('full_name')}}")
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
div(tg-projects-listing)
|
Loading…
Reference in New Issue