From 830cec54c5c36cb2f0fddbf4aeaf91469e2d64b9 Mon Sep 17 00:00:00 2001 From: Alexandre Tuleu Date: Fri, 12 Feb 2016 14:36:59 +0100 Subject: [PATCH] Makes album display a bit nicer --- test/specs/album-service_test.js | 20 +++++--------------- webapp/js/services.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/test/specs/album-service_test.js b/test/specs/album-service_test.js index 75aa4a1..bc16ca4 100644 --- a/test/specs/album-service_test.js +++ b/test/specs/album-service_test.js @@ -67,47 +67,38 @@ describe('Service: albumService', function() { "8179": { "serieDisplay": "Mortes saisons", "titleDisplay": "Mortes saisons", - "titleWithSerie": "Mortes saisons" }, "44989": { - "serieDisplay": "Abel Dopeulapeul", + "serieDisplay": "Abel Dopeulapeul 2", "titleDisplay" : "Sale temps pour mourir", - "titleWithSerie": "Abel Dopeulapeul 2: Sale temps pour mourir" }, "58595": { "serieDisplay": "", "titleDisplay": "Des fourmis dans les jambes", - "titleWithSerie": "Des fourmis dans les jambes" }, "9935": { - "serieDisplay": "Bizu", + "serieDisplay": "Bizu 5", "titleDisplay": "La croisière fantôme", - "titleWithSerie": "Bizu 5: La croisière fantôme" }, "164": { - "serieDisplay": "Les Eaux de Mortelune", + "serieDisplay": "Les Eaux de Mortelune 5", "titleDisplay": "Vague à lames", - "titleWithSerie": "Les Eaux de Mortelune 5: Vague à lames" }, "32043": { - "serieDisplay": "Accros de ...", + "serieDisplay": "Accros de ... 2", "titleDisplay": "Rap", - "titleWithSerie": "Accros de ... 2: Rap" }, "46005": { - "serieDisplay": "Chick Bill", + "serieDisplay": "Chick Bill 23", "titleDisplay": "Le témoin du Rio Grande", - "titleWithSerie": "Chick Bill 23: Rap: Le témoin du Rio Grande" }, "15875": { "serieDisplay": "Donc, Jean", "titleDisplay": "...donc, Jean.", - "titleWithSerie": "...donc, Jean." }, "84448": { "serieDisplay": "Black Crow", "titleDisplay": "Black Crow raconte L'Hermione - La Conspiration pour la liberté", - "titleWithSerie" : "Black Crow raconte L'Hermione - La Conspiration pour la liberté" }, }; @@ -126,7 +117,6 @@ describe('Service: albumService', function() { expect(err).toBe(undefined); expect(album.serieDisplay).toBe(expectedData[key].serieDisplay); expect(album.titleDisplay).toBe(expectedData[key].titleDisplay); - expect(album.titleWithSerie).toBe(expectedData[key].titleWithSerie); } diff --git a/webapp/js/services.js b/webapp/js/services.js index 5affabc..97bc92c 100644 --- a/webapp/js/services.js +++ b/webapp/js/services.js @@ -1,11 +1,32 @@ var services = angular.module('satbd.satellite.bar.services',[]) services.factory('albumService',['$http','$log','$q', function($http,$log,$q) { + var determinantRegexp = /^(.*) \(([Ll][eas']+)\)$/; + + var removeSerie = /^\(.*\) .*$/; + + function cleanupName(name) { + matches = name.match(determinantRegexp); + if (matches == null) { + return name; + } + return matches[2] + ' ' + matches[1]; + } + function cleanupFields(album) { album.serie = album.série; album.série = undefined; album.editeur = album.éditeur; album.éditeur = undefined; + if (removeSerie.test(album.serie) == true) { + album.serieDisplay = ''; + } else { + album.serieDisplay = cleanupName(album.serie); + if ( album.Num > -1 ) { + album.serieDisplay += ' ' + album.Num; + } + } + album.titleDisplay = cleanupName(album.titre); return album; } function get(id) {