diff --git a/app/modules/components/project-logo-big-src/project-logo-big-src.directive.coffee b/app/modules/components/project-logo-big-src/project-logo-big-src.directive.coffee new file mode 100644 index 00000000..2c271629 --- /dev/null +++ b/app/modules/components/project-logo-big-src/project-logo-big-src.directive.coffee @@ -0,0 +1,48 @@ +### +# Copyright (C) 2014-2016 Taiga Agile LLC +# +# 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 . +# +# 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) diff --git a/app/modules/components/project-logo-small-src/project-logo-small-src.directive.coffee b/app/modules/components/project-logo-small-src/project-logo-small-src.directive.coffee new file mode 100644 index 00000000..51900e2e --- /dev/null +++ b/app/modules/components/project-logo-small-src/project-logo-small-src.directive.coffee @@ -0,0 +1,48 @@ +### +# Copyright (C) 2014-2016 Taiga Agile LLC +# +# 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 . +# +# 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) diff --git a/app/modules/components/project-logo-src/project-logo-src.directive.coffee b/app/modules/components/project-logo-src/project-logo-src.directive.coffee deleted file mode 100644 index 861930e0..00000000 --- a/app/modules/components/project-logo-src/project-logo-src.directive.coffee +++ /dev/null @@ -1,77 +0,0 @@ -### -# Copyright (C) 2014-2016 Taiga Agile LLC -# -# 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 . -# -# 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) diff --git a/app/modules/discover/components/featured-projects/featured-projects.jade b/app/modules/discover/components/featured-projects/featured-projects.jade index 53c3514b..4ad7d167 100644 --- a/app/modules/discover/components/featured-projects/featured-projects.jade +++ b/app/modules/discover/components/featured-projects/featured-projects.jade @@ -17,7 +17,7 @@ title="{{::project.get('name')}}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) h2.project-card-name diff --git a/app/modules/discover/components/highlighted/highlighted.jade b/app/modules/discover/components/highlighted/highlighted.jade index 96031ebf..4559e647 100644 --- a/app/modules/discover/components/highlighted/highlighted.jade +++ b/app/modules/discover/components/highlighted/highlighted.jade @@ -13,7 +13,7 @@ title="{{::project.get('name')}}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) .project-data-container diff --git a/app/modules/discover/discover-search/discover-search.jade b/app/modules/discover/discover-search/discover-search.jade index 937e45fa..0e8579ab 100644 --- a/app/modules/discover/discover-search/discover-search.jade +++ b/app/modules/discover/discover-search/discover-search.jade @@ -33,7 +33,7 @@ div(tg-discover-search) title="{{ ::project.get('name') }}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) .list-itemtype-project-data diff --git a/app/modules/home/projects/home-project-list.jade b/app/modules/home/projects/home-project-list.jade index a66a41c2..15d2775e 100644 --- a/app/modules/home/projects/home-project-list.jade +++ b/app/modules/home/projects/home-project-list.jade @@ -15,7 +15,7 @@ section.home-project-list(ng-if="vm.projects.size") title="{{::project.get('name')}}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) h2.project-card-name diff --git a/app/modules/profile/profile-favs/items/project.jade b/app/modules/profile/profile-favs/items/project.jade index 827eff4f..3b7a3913 100644 --- a/app/modules/profile/profile-favs/items/project.jade +++ b/app/modules/profile/profile-favs/items/project.jade @@ -8,7 +8,7 @@ title="{{ ::vm.item.get('name') }}" ) img( - tg-project-logo-src="vm.item" + tg-project-logo-small-src="vm.item" title="{{ ::vm.item.get('name') }}" ) diff --git a/app/modules/profile/profile-projects/profile-projects.jade b/app/modules/profile/profile-projects/profile-projects.jade index 28c2ef45..30861ed5 100644 --- a/app/modules/profile/profile-projects/profile-projects.jade +++ b/app/modules/profile/profile-projects/profile-projects.jade @@ -20,7 +20,7 @@ section.profile-projects title="{{ ::project.get('name') }}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) .project-list-single-title diff --git a/app/modules/projects/listing/projects-listing.jade b/app/modules/projects/listing/projects-listing.jade index 3e1e0de9..529d620f 100644 --- a/app/modules/projects/listing/projects-listing.jade +++ b/app/modules/projects/listing/projects-listing.jade @@ -32,7 +32,7 @@ title="{{ ::project.get('name') }}" ) img( - tg-project-logo-src="::project" + tg-project-logo-small-src="::project" alt="{{::project.get('name')}}" ) .list-itemtype-project-data diff --git a/app/modules/projects/project/project.jade b/app/modules/projects/project/project.jade index b646fbff..6820cc8b 100644 --- a/app/modules/projects/project/project.jade +++ b/app/modules/projects/project/project.jade @@ -8,7 +8,7 @@ div.wrapper title="{{::project.get('name')}}" ) img( - tg-project-logo-src="vm.project" + tg-project-logo-big-src="vm.project" alt="{{::vm.project.get('name')}}" ) .single-project-title-wrapper diff --git a/app/modules/services/project-logo.service.coffee b/app/modules/services/project-logo.service.coffee new file mode 100644 index 00000000..130d9ded --- /dev/null +++ b/app/modules/services/project-logo.service.coffee @@ -0,0 +1,47 @@ +### +# Copyright (C) 2014-2015 Taiga Agile LLC +# +# 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 . +# +# 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) diff --git a/app/modules/services/project-logo.service.spec.coffee b/app/modules/services/project-logo.service.spec.coffee new file mode 100644 index 00000000..1c6cae74 --- /dev/null +++ b/app/modules/services/project-logo.service.spec.coffee @@ -0,0 +1,42 @@ +### +# Copyright (C) 2014-2015 Taiga Agile LLC +# +# 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 . +# +# 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 )'); diff --git a/app/partials/admin/admin-project-profile.jade b/app/partials/admin/admin-project-profile.jade index c786f932..a44a1e8d 100644 --- a/app/partials/admin/admin-project-profile.jade +++ b/app/partials/admin/admin-project-profile.jade @@ -22,7 +22,7 @@ div.wrapper( .project-details-image(tg-project-logo) fieldset.image-container img.image( - tg-project-logo-src="project._attrs" + tg-project-logo-big-src="project._attrs" alt="logo" ) .loading-overlay