project-log-small & project-logo-big directives, fix #3855
parent
63912abf8e
commit
c0e2aea275
|
@ -0,0 +1,48 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014-2016 Taiga Agile LLC <taiga@taiga.io>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: project-logo-big-src.directive.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
ProjectLogoBigSrcDirective = (projectLogoService) ->
|
||||||
|
link = (scope, el, attrs) ->
|
||||||
|
scope.$watch 'project', (project) ->
|
||||||
|
project = Immutable.fromJS(project) # Necesary for old code
|
||||||
|
|
||||||
|
return if not project
|
||||||
|
|
||||||
|
projectLogo = project.get('logo_big_url')
|
||||||
|
|
||||||
|
if projectLogo
|
||||||
|
el.attr('src', projectLogo)
|
||||||
|
el.css('background', "")
|
||||||
|
else
|
||||||
|
logo = projectLogoService.getDefaultProjectLogo(project.get('slug'), project.get('id'))
|
||||||
|
el.attr('src', logo.src)
|
||||||
|
el.css('background', logo.color)
|
||||||
|
|
||||||
|
return {
|
||||||
|
link: link
|
||||||
|
scope: {
|
||||||
|
project: "=tgProjectLogoBigSrc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectLogoBigSrcDirective.$inject = [
|
||||||
|
"tgProjectLogoService"
|
||||||
|
]
|
||||||
|
|
||||||
|
angular.module("taigaComponents").directive("tgProjectLogoBigSrc", ProjectLogoBigSrcDirective)
|
|
@ -0,0 +1,48 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014-2016 Taiga Agile LLC <taiga@taiga.io>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: project-logo-small-src.directive.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
ProjectLogoSmallSrcDirective = (projectLogoService) ->
|
||||||
|
link = (scope, el, attrs) ->
|
||||||
|
scope.$watch 'project', (project) ->
|
||||||
|
project = Immutable.fromJS(project) # Necesary for old code
|
||||||
|
|
||||||
|
return if not project
|
||||||
|
|
||||||
|
projectLogo = project.get('logo_small_url')
|
||||||
|
|
||||||
|
if projectLogo
|
||||||
|
el.attr('src', projectLogo)
|
||||||
|
el.css('background', "")
|
||||||
|
else
|
||||||
|
logo = projectLogoService.getDefaultProjectLogo(project.get('slug'), project.get('id'))
|
||||||
|
el.attr('src', logo.src)
|
||||||
|
el.css('background', logo.color)
|
||||||
|
|
||||||
|
return {
|
||||||
|
link: link
|
||||||
|
scope: {
|
||||||
|
project: "=tgProjectLogoSmallSrc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectLogoSmallSrcDirective.$inject = [
|
||||||
|
"tgProjectLogoService"
|
||||||
|
]
|
||||||
|
|
||||||
|
angular.module("taigaComponents").directive("tgProjectLogoSmallSrc", ProjectLogoSmallSrcDirective)
|
|
@ -1,77 +0,0 @@
|
||||||
###
|
|
||||||
# Copyright (C) 2014-2016 Taiga Agile LLC <taiga@taiga.io>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
# File: project-logo.directive.coffee
|
|
||||||
###
|
|
||||||
|
|
||||||
|
|
||||||
IMAGES = [
|
|
||||||
"/#{window._version}/images/project-logos/project-logo-01.png"
|
|
||||||
"/#{window._version}/images/project-logos/project-logo-02.png"
|
|
||||||
"/#{window._version}/images/project-logos/project-logo-03.png"
|
|
||||||
"/#{window._version}/images/project-logos/project-logo-04.png"
|
|
||||||
"/#{window._version}/images/project-logos/project-logo-05.png"
|
|
||||||
]
|
|
||||||
|
|
||||||
COLORS = [
|
|
||||||
"rgba( 153, 214, 220, 1 )"
|
|
||||||
"rgba( 213, 156, 156, 1 )"
|
|
||||||
"rgba( 214, 161, 212, 1 )"
|
|
||||||
"rgba( 164, 162, 219, 1 )"
|
|
||||||
"rgba( 152, 224, 168, 1 )"
|
|
||||||
]
|
|
||||||
|
|
||||||
LOGOS = _.cartesianProduct(IMAGES, COLORS)
|
|
||||||
|
|
||||||
|
|
||||||
ProjectLogoSrcDirective = ($parse) ->
|
|
||||||
_getDefaultProjectLogo = (project) ->
|
|
||||||
key = "#{project.get("slug")}-#{project.get("id")}"
|
|
||||||
idx = murmurhash3_32_gc(key, 42) %% LOGOS.length
|
|
||||||
logo = LOGOS[idx]
|
|
||||||
|
|
||||||
return { src: logo[0], color: logo[1] }
|
|
||||||
|
|
||||||
link = (scope, el, attrs) ->
|
|
||||||
scope.$watch "project", (project) ->
|
|
||||||
project = Immutable.fromJS(project) # Necesary for old code
|
|
||||||
|
|
||||||
return if not project
|
|
||||||
|
|
||||||
projectLogo = project.get('logo_big_url')
|
|
||||||
|
|
||||||
if projectLogo
|
|
||||||
el.attr("src", projectLogo)
|
|
||||||
el.css('background', "")
|
|
||||||
else
|
|
||||||
logo = _getDefaultProjectLogo(project)
|
|
||||||
el.attr("src", logo.src)
|
|
||||||
el.css('background', logo.color)
|
|
||||||
|
|
||||||
scope.$on "$destroy", -> el.off()
|
|
||||||
|
|
||||||
return {
|
|
||||||
link: link
|
|
||||||
scope: {
|
|
||||||
project: "=tgProjectLogoSrc"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectLogoSrcDirective.$inject = [
|
|
||||||
"$parse"
|
|
||||||
]
|
|
||||||
|
|
||||||
angular.module("taigaComponents").directive("tgProjectLogoSrc", ProjectLogoSrcDirective)
|
|
|
@ -17,7 +17,7 @@
|
||||||
title="{{::project.get('name')}}"
|
title="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
h2.project-card-name
|
h2.project-card-name
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
title="{{::project.get('name')}}"
|
title="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
.project-data-container
|
.project-data-container
|
||||||
|
|
|
@ -33,7 +33,7 @@ div(tg-discover-search)
|
||||||
title="{{ ::project.get('name') }}"
|
title="{{ ::project.get('name') }}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
.list-itemtype-project-data
|
.list-itemtype-project-data
|
||||||
|
|
|
@ -15,7 +15,7 @@ section.home-project-list(ng-if="vm.projects.size")
|
||||||
title="{{::project.get('name')}}"
|
title="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
h2.project-card-name
|
h2.project-card-name
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
title="{{ ::vm.item.get('name') }}"
|
title="{{ ::vm.item.get('name') }}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="vm.item"
|
tg-project-logo-small-src="vm.item"
|
||||||
title="{{ ::vm.item.get('name') }}"
|
title="{{ ::vm.item.get('name') }}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ section.profile-projects
|
||||||
title="{{ ::project.get('name') }}"
|
title="{{ ::project.get('name') }}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
.project-list-single-title
|
.project-list-single-title
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
title="{{ ::project.get('name') }}"
|
title="{{ ::project.get('name') }}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="::project"
|
tg-project-logo-small-src="::project"
|
||||||
alt="{{::project.get('name')}}"
|
alt="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
.list-itemtype-project-data
|
.list-itemtype-project-data
|
||||||
|
|
|
@ -8,7 +8,7 @@ div.wrapper
|
||||||
title="{{::project.get('name')}}"
|
title="{{::project.get('name')}}"
|
||||||
)
|
)
|
||||||
img(
|
img(
|
||||||
tg-project-logo-src="vm.project"
|
tg-project-logo-big-src="vm.project"
|
||||||
alt="{{::vm.project.get('name')}}"
|
alt="{{::vm.project.get('name')}}"
|
||||||
)
|
)
|
||||||
.single-project-title-wrapper
|
.single-project-title-wrapper
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014-2015 Taiga Agile LLC <taiga@taiga.io>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: project-logo.service.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
class ProjectLogoService
|
||||||
|
constructor: () ->
|
||||||
|
IMAGES = [
|
||||||
|
"/#{window._version}/images/project-logos/project-logo-01.png"
|
||||||
|
"/#{window._version}/images/project-logos/project-logo-02.png"
|
||||||
|
"/#{window._version}/images/project-logos/project-logo-03.png"
|
||||||
|
"/#{window._version}/images/project-logos/project-logo-04.png"
|
||||||
|
"/#{window._version}/images/project-logos/project-logo-05.png"
|
||||||
|
]
|
||||||
|
|
||||||
|
COLORS = [
|
||||||
|
"rgba( 153, 214, 220, 1 )"
|
||||||
|
"rgba( 213, 156, 156, 1 )"
|
||||||
|
"rgba( 214, 161, 212, 1 )"
|
||||||
|
"rgba( 164, 162, 219, 1 )"
|
||||||
|
"rgba( 152, 224, 168, 1 )"
|
||||||
|
]
|
||||||
|
|
||||||
|
@.logos = _.cartesianProduct(IMAGES, COLORS)
|
||||||
|
|
||||||
|
getDefaultProjectLogo: (slug, id) ->
|
||||||
|
key = "#{slug}-#{id}"
|
||||||
|
idx = murmurhash3_32_gc(key, 42) %% @.logos.length
|
||||||
|
logo = @.logos[idx]
|
||||||
|
|
||||||
|
return { src: logo[0], color: logo[1] }
|
||||||
|
|
||||||
|
angular.module("taigaCommon").service("tgProjectLogoService", ProjectLogoService)
|
|
@ -0,0 +1,42 @@
|
||||||
|
###
|
||||||
|
# Copyright (C) 2014-2015 Taiga Agile LLC <taiga@taiga.io>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# File: project-logo.service.spec.coffee
|
||||||
|
###
|
||||||
|
|
||||||
|
describe "tgProjectLogoService", ->
|
||||||
|
$provide = null
|
||||||
|
projectLogoService = null
|
||||||
|
|
||||||
|
_inject = ->
|
||||||
|
inject (_tgProjectLogoService_) ->
|
||||||
|
projectLogoService = _tgProjectLogoService_
|
||||||
|
|
||||||
|
_setup = ->
|
||||||
|
_inject()
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
window._version = '123'
|
||||||
|
module "taigaCommon"
|
||||||
|
|
||||||
|
_setup()
|
||||||
|
|
||||||
|
it "get default project logo", () ->
|
||||||
|
|
||||||
|
logo = projectLogoService.getDefaultProjectLogo('slug/slug', 2)
|
||||||
|
|
||||||
|
expect(logo.src).to.be.equal('/123/images/project-logos/project-logo-04.png');
|
||||||
|
expect(logo.color).to.be.equal('rgba( 152, 224, 168, 1 )');
|
|
@ -22,7 +22,7 @@ div.wrapper(
|
||||||
.project-details-image(tg-project-logo)
|
.project-details-image(tg-project-logo)
|
||||||
fieldset.image-container
|
fieldset.image-container
|
||||||
img.image(
|
img.image(
|
||||||
tg-project-logo-src="project._attrs"
|
tg-project-logo-big-src="project._attrs"
|
||||||
alt="logo"
|
alt="logo"
|
||||||
)
|
)
|
||||||
.loading-overlay
|
.loading-overlay
|
||||||
|
|
Loading…
Reference in New Issue