page controller
parent
776c1fe019
commit
0c9b2f78b3
|
@ -39,10 +39,31 @@ taiga.sessionId = taiga.generateUniqueSessionIdentifier()
|
||||||
configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEventsProvider, tgLoaderProvider,
|
configure = ($routeProvider, $locationProvider, $httpProvider, $provide, $tgEventsProvider, tgLoaderProvider,
|
||||||
$compileProvider, $translateProvider) ->
|
$compileProvider, $translateProvider) ->
|
||||||
$routeProvider.when("/",
|
$routeProvider.when("/",
|
||||||
{templateUrl: "home/home-page.html", resolve: {loader: tgLoaderProvider.add()}})
|
{
|
||||||
|
templateUrl: "home/home-page.html",
|
||||||
|
resolve: {
|
||||||
|
loader: tgLoaderProvider.add(true),
|
||||||
|
pageParams: -> {
|
||||||
|
"title": "PROJECT.WELCOME"
|
||||||
|
"authRequired": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
$routeProvider.when("/projects/",
|
$routeProvider.when("/projects/",
|
||||||
{templateUrl: "projects/projects-page.html", resolve: {loader: tgLoaderProvider.add(true)}})
|
{
|
||||||
|
templateUrl: "projects/projects-page.html",
|
||||||
|
resolve: {
|
||||||
|
loader: tgLoaderProvider.add(true),
|
||||||
|
pageParams: -> {
|
||||||
|
"title": "PROJECT.SECTION_PROJECTS"
|
||||||
|
"authRequired": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
controller: "Page"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
$routeProvider.when("/project/:pslug/",
|
$routeProvider.when("/project/:pslug/",
|
||||||
{templateUrl: "project/project.html"})
|
{templateUrl: "project/project.html"})
|
||||||
|
@ -362,6 +383,7 @@ modules = [
|
||||||
"taigaComponents",
|
"taigaComponents",
|
||||||
"taigaProfile",
|
"taigaProfile",
|
||||||
"taigaHome",
|
"taigaHome",
|
||||||
|
"taigaPage",
|
||||||
|
|
||||||
# template cache
|
# template cache
|
||||||
"templates",
|
"templates",
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
div(ng-controller="HomePage", tg-home)
|
div(tg-home)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
class PageController extends taiga.Controller
|
||||||
|
@.$inject = [
|
||||||
|
"$tgAuth",
|
||||||
|
"$appTitle",
|
||||||
|
"$translate",
|
||||||
|
"$tgLocation",
|
||||||
|
"$tgNavUrls",
|
||||||
|
"pageParams"
|
||||||
|
]
|
||||||
|
|
||||||
|
constructor: (@auth, @appTitle, @translate, @location, @navUrls, @pageParams) ->
|
||||||
|
if @pageParams.authRequired && !@auth.isAuthenticated()
|
||||||
|
@location.path(@navUrls.resolve("login"))
|
||||||
|
|
||||||
|
if @pageParams.title
|
||||||
|
@translate(@pageParams.title).then (text) => @appTitle.set(text)
|
||||||
|
|
||||||
|
angular.module("taigaPage").controller("Page", PageController)
|
|
@ -0,0 +1,123 @@
|
||||||
|
describe "PageController", ->
|
||||||
|
pageCtrl = null
|
||||||
|
provide = null
|
||||||
|
controller = null
|
||||||
|
mocks = {}
|
||||||
|
|
||||||
|
_mockPageParams = () ->
|
||||||
|
mocks.pageParams = {}
|
||||||
|
|
||||||
|
provide.value "pageParams", mocks.pageParams
|
||||||
|
|
||||||
|
_mockAuth = () ->
|
||||||
|
mocks.auth = {
|
||||||
|
isAuthenticated: sinon.stub()
|
||||||
|
}
|
||||||
|
|
||||||
|
provide.value "$tgAuth", mocks.auth
|
||||||
|
|
||||||
|
_mockAppTitle = () ->
|
||||||
|
mocks.appTitle = {
|
||||||
|
set: sinon.spy()
|
||||||
|
}
|
||||||
|
|
||||||
|
provide.value "$appTitle", mocks.appTitle
|
||||||
|
|
||||||
|
_mockLocation = () ->
|
||||||
|
mocks.location = {
|
||||||
|
path: sinon.spy()
|
||||||
|
}
|
||||||
|
|
||||||
|
provide.value "$tgLocation", mocks.location
|
||||||
|
|
||||||
|
_mockNavUrls = () ->
|
||||||
|
mocks.navUrls = {
|
||||||
|
resolve: sinon.stub()
|
||||||
|
}
|
||||||
|
|
||||||
|
provide.value "$tgNavUrls", mocks.navUrls
|
||||||
|
|
||||||
|
_mockTranslate = () ->
|
||||||
|
mocks.translate = sinon.stub()
|
||||||
|
|
||||||
|
provide.value "$translate", mocks.translate
|
||||||
|
|
||||||
|
_mocks = () ->
|
||||||
|
module ($provide) ->
|
||||||
|
provide = $provide
|
||||||
|
_mockAppTitle()
|
||||||
|
_mockPageParams()
|
||||||
|
_mockAuth()
|
||||||
|
_mockLocation()
|
||||||
|
_mockNavUrls()
|
||||||
|
_mockTranslate()
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
module "taigaPage"
|
||||||
|
|
||||||
|
_mocks()
|
||||||
|
|
||||||
|
inject ($controller) ->
|
||||||
|
controller = $controller
|
||||||
|
|
||||||
|
describe "auth", () ->
|
||||||
|
it "if auth is required and the user is not logged redirect to login page", () ->
|
||||||
|
locationPath = "location-path"
|
||||||
|
|
||||||
|
mocks.pageParams.authRequired = true
|
||||||
|
mocks.auth.isAuthenticated.returns(false)
|
||||||
|
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
||||||
|
|
||||||
|
pageCtrl = controller "Page",
|
||||||
|
$scope: {}
|
||||||
|
|
||||||
|
expect(mocks.location.path.withArgs(locationPath)).have.been.calledOnce
|
||||||
|
|
||||||
|
it "if auth is not required no redirect to login page", () ->
|
||||||
|
locationPath = "location-path"
|
||||||
|
|
||||||
|
mocks.pageParams.authRequired = false
|
||||||
|
mocks.auth.isAuthenticated.returns(false)
|
||||||
|
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
||||||
|
|
||||||
|
pageCtrl = controller "Page",
|
||||||
|
$scope: {}
|
||||||
|
|
||||||
|
expect(mocks.location.path).have.callCount(0)
|
||||||
|
|
||||||
|
it "if auth is required and the user is logged no redirect", () ->
|
||||||
|
locationPath = "location-path"
|
||||||
|
|
||||||
|
mocks.pageParams.authRequired = true
|
||||||
|
mocks.auth.isAuthenticated.returns(true)
|
||||||
|
mocks.navUrls.resolve.withArgs("login").returns(locationPath)
|
||||||
|
|
||||||
|
pageCtrl = controller "Page",
|
||||||
|
$scope: {}
|
||||||
|
|
||||||
|
expect(mocks.location.path).have.callCount(0)
|
||||||
|
|
||||||
|
describe "page title", () ->
|
||||||
|
it "if title is defined set it", () ->
|
||||||
|
thenStub = sinon.stub()
|
||||||
|
|
||||||
|
mocks.pageParams.title = "TITLE"
|
||||||
|
mocks.translate.withArgs("TITLE").returns({
|
||||||
|
then: thenStub
|
||||||
|
})
|
||||||
|
|
||||||
|
pageCtrl = controller "Page",
|
||||||
|
$scope: {}
|
||||||
|
|
||||||
|
thenStub.callArg(0, "TITLE")
|
||||||
|
|
||||||
|
expect(mocks.appTitle.set.withArgs("TITLE")).have.been.calledOnce
|
||||||
|
|
||||||
|
it "if title is not defined not call appTitle", () ->
|
||||||
|
pageCtrl = controller "Page",
|
||||||
|
$scope: {}
|
||||||
|
|
||||||
|
expect(mocks.translate).have.callCount(0)
|
||||||
|
expect(mocks.appTitle.set.withArgs("TITLE")).have.callCount(0)
|
|
@ -0,0 +1 @@
|
||||||
|
module = angular.module("taigaPage", [])
|
|
@ -1,26 +0,0 @@
|
||||||
class ProjectsPageController extends taiga.Controller
|
|
||||||
@.$inject = [
|
|
||||||
"$scope",
|
|
||||||
"$q",
|
|
||||||
"$tgResources",
|
|
||||||
"$rootScope",
|
|
||||||
"$tgNavUrls",
|
|
||||||
"$tgAuth",
|
|
||||||
"$tgLocation",
|
|
||||||
"$appTitle",
|
|
||||||
"$projectUrl",
|
|
||||||
"$tgConfig",
|
|
||||||
"tgLoader",
|
|
||||||
"tgProjectsService",
|
|
||||||
"$translate"
|
|
||||||
]
|
|
||||||
|
|
||||||
constructor: (@scope, @q, @rs, @rootscope, @navUrls, @auth, @location,
|
|
||||||
@appTitle, @projectUrl, @config, tgLoader, @projectsService, @translate) ->
|
|
||||||
|
|
||||||
if !@auth.isAuthenticated()
|
|
||||||
@location.path(@navUrls.resolve("login"))
|
|
||||||
|
|
||||||
@appTitle.set(@translate.instant("PROJECT.SECTION_PROJECTS"))
|
|
||||||
|
|
||||||
angular.module("taigaProjects").controller("ProjectsPage", ProjectsPageController)
|
|
|
@ -1 +1 @@
|
||||||
div(ng-controller="ProjectsPage", tg-projects-listing)
|
div(tg-projects-listing)
|
||||||
|
|
Loading…
Reference in New Issue