(really) better management of slideshowModel with new api.
authorcavaliet
Mon, 06 Oct 2014 22:52:30 +0200
changeset 8 824c87a9084c
parent 7 e70f1c4785f3
child 9 962604899225
(really) better management of slideshowModel with new api.
client/app/app.js
client/app/gallery/gallery.css
client/app/gallery/gallery.html
client/app/home/home_controller.js
client/app/index.html
client/app/search/search.html
client/app/search/search_controller.js
client/app/slideshow/slideshow.css
client/app/slideshow/slideshow.html
client/app/slideshow/slideshow_controller.js
--- a/client/app/app.js	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/app.js	Mon Oct 06 22:52:30 2014 +0200
@@ -60,9 +60,26 @@
                     getJsonp: {
                         method: 'JSONP',
                         params: params,
-                        isArray: false
+                        isArray: false,
+                        transformResponse: function(data){
+                            // Transform meta list into meta dict
+                            var nb = data.hits.length;
+                            for(var i=0;i<nb;i++){
+                                var nb_metas = data.hits[i].metas.length;
+                                data.hits[i].metas_dict = {};
+                                for(var j=0;j<nb_metas;j++){
+                                    if(typeof data.hits[i].metas[j].images==='undefined'){
+                                        data.hits[i].metas_dict[data.hits[i].metas[j].name] = data.hits[i].metas[j].value;
+                                    }
+                                    else{
+                                        data.hits[i].metas_dict.images = data.hits[i].metas[j].images[0].value;
+                                    }
+                                }
+                            }
+                            return data;
+                        }
                     }
-                }).getJsonp();
+                });
         };
     });
 
--- a/client/app/gallery/gallery.css	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/gallery/gallery.css	Mon Oct 06 22:52:30 2014 +0200
@@ -25,6 +25,7 @@
 
 .gallery .item img {
     margin: 0 auto;
+    max-height: 100%;
 }
 
 .gallery-buttons{
--- a/client/app/gallery/gallery.html	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/gallery/gallery.html	Mon Oct 06 22:52:30 2014 +0200
@@ -2,9 +2,9 @@
 <p>{{ gallery.description }}</p>
 <h4 class="subtitle">{{ gallery.images.length }} points d'intérêt</h4>
 <ul class="list-unstyled list-inline row gallery">
-  <li class="col-md-3 item" ng-repeat="i in gallery.images">
+  <li class="col-md-3 item" ng-repeat="i in gallery.hits">
     <div class="img-ctn">
-        <img class="img img-responsive image" src="{{ i.url }}" />
+        <img class="img img-responsive image" src="{{ i.metas_dict.images }}" />
         <p>{{ i.title }}</p>
         <div class="gallery-buttons">
           <a class="btn btn-default" href="#/slideshow/edit/{{ $index }}"><span class="glyphicon glyphicon-pencil"></span></a>
--- a/client/app/home/home_controller.js	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/home/home_controller.js	Mon Oct 06 22:52:30 2014 +0200
@@ -15,6 +15,19 @@
       $scope.searchSubmit = function(){
           $location.path('/search/' + $scope.q);
       };
+    })
+    .filter('meta', function() {
+        return function(input, metaName) {
+            var nb = input.length, i = 0, found = false;
+            while(found===false && i<nb){
+                if(input[i].name===metaName){
+                    found = true;
+                    return input[i].value;
+                }
+                i++;
+            }
+            return '';
+        };
     });
 
 })();
--- a/client/app/index.html	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/index.html	Mon Oct 06 22:52:30 2014 +0200
@@ -57,7 +57,6 @@
               record: angular.fromJson('{"record": "record value"}'),
               urls: {
                   base_static: "./",
-                  slideshowUrl: "data/slideshow.json",
                   searchUrl: "http://ammico.labs.exalead.com/search-api"
               }
           });
--- a/client/app/search/search.html	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/search/search.html	Mon Oct 06 22:52:30 2014 +0200
@@ -3,7 +3,7 @@
 <div ng-if="results.nhits>0">
   <div class="row search-item" ng-repeat="h in results.hits" ng-init="h.imgbig=false">
       <div ng-class="{'col-md-5': h.imgbig, 'col-md-3': !h.imgbig}">
-        <img src="{{ h.metas_dict.images }}" ng-class="{'search-img-max': !h.imgbig}"/>
+        <img src="{{ h.metas_dict.images }}" ng-class="{'search-img-max': !h.imgbig}" ng-click="h.imgbig=!h.imgbig"/>
       </div>
       <div ng-class="{'col-md-5': h.imgbig, 'col-md-7': !h.imgbig}">
 	      <p><strong>Nom&nbsp;:</strong> {{ h.metas_dict.name }}</p>
--- a/client/app/search/search_controller.js	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/search/search_controller.js	Mon Oct 06 22:52:30 2014 +0200
@@ -12,43 +12,7 @@
     .controller('searchCtrl', function($scope, $location, $routeParams, searchApi){
       console.log('search 6',$scope, $location, $routeParams);
       $scope.q = $routeParams.q || '';
-      searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).$promise.then(
-          //success
-          function( data ){
-              // Transform meta list into meta dict
-              var nb = data.hits.length;
-              for(var i=0;i<nb;i++){
-                  var nb_metas = data.hits[i].metas.length;
-                  data.hits[i].metas_dict = {};
-                  for(var j=0;j<nb_metas;j++){
-                      if(typeof data.hits[i].metas[j].images==='undefined'){
-                          data.hits[i].metas_dict[data.hits[i].metas[j].name] = data.hits[i].metas[j].value;
-                      }
-                      else{
-                          data.hits[i].metas_dict.images = data.hits[i].metas[j].images[0].value;
-                      }
-                  }
-              }
-              $scope.results = data;
-          },
-          //error
-          function( error ){
-              alert('Erreur avec la requête', error);
-          }
-      );
-    })
-    .filter('meta', function() {
-        return function(input, metaName) {
-            var nb = input.length, i = 0, found = false;
-            while(found===false && i<nb){
-                if(input[i].name===metaName){
-                    found = true;
-                    return input[i].value;
-                }
-                i++;
-            }
-            return '';
-        };
+      $scope.results = searchApi.searchResource({q:$scope.q, of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp();
     });
 
 })();
--- a/client/app/slideshow/slideshow.css	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/slideshow/slideshow.css	Mon Oct 06 22:52:30 2014 +0200
@@ -17,6 +17,11 @@
     right: 2%;
 }
 
+.carousel-holder img{
+    max-height: 500px;
+	max-width: 100%;
+}
+
 .original-text {
     font-style: italic;
 }
--- a/client/app/slideshow/slideshow.html	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/slideshow/slideshow.html	Mon Oct 06 22:52:30 2014 +0200
@@ -2,24 +2,24 @@
 <p>{{ slideshow.description }}</p>
 <div class="carousel-holder row">
   <carousel>
-    <slide ng-repeat="slide in slideshow.images" active="slide.active">
+    <slide ng-repeat="slide in slideshow.hits" active="slide.active">
         <div class="row">
           <div class="col-md-6 col-md-offset-1">
-            <img ng-src="{{slide.url}}" style="margin:auto;">
+            <img ng-src="{{ slide.metas_dict.images }}" style="margin:auto;">
           </div>
           <div class="carousel-caption col-md-4">
             <slide-editor index="{{$index}}"></slide-editor>
             <hr/>
-            <h4 class="original-text">{{ slide.metas|meta:"name" }}</h4>
-            <p class="original-text">{{ slide.metas|meta:"description" }}</p>
+            <h4 class="original-text">{{ slide.metas_dict.name }}</h4>
+            <p class="original-text">{{ slide.metas_dict.description }}</p>
             <p class="text-right"><a class="btn btn-default" ng-click="h.imgbig=!h.imgbig"><span class="glyphicon glyphicon-eye-open"></span></a></p>
             <div ng-show="h.imgbig">
-              <p><small><strong>Classification&nbsp;:</strong> {{ slide.metas|meta:"classification" }}</small></p>
-              <p><small><strong>Current Custody&nbsp;:</strong> {{ slide.metas|meta:"currentcustody" }}</small></p>
-              <p><small><strong>Former Custody&nbsp;:</strong> {{ slide.metas|meta:"formercustody" }}</small></p>
-              <p><small><strong>Mesures&nbsp;:</strong> {{ slide.metas|meta:"measures" }}</small></p>
-              <p><small><strong>Acteurs&nbsp;:</strong> {{ slide.metas|meta:"actors" }}</small></p>
-              <p><small><strong>Lieux&nbsp;:</strong> {{ slide.metas|meta:"places" }}</small></p>
+              <p><small><strong>Classification&nbsp;:</strong> {{ slide.metas_dict.classification }}</small></p>
+              <p><small><strong>Current Custody&nbsp;:</strong> {{ slide.metas_dict.currentcustody }}</small></p>
+              <p><small><strong>Former Custody&nbsp;:</strong> {{ slide.metas_dict.formercustody }}</small></p>
+              <p><small><strong>Mesures&nbsp;:</strong> {{ slide.metas_dict.measures }}</small></p>
+              <p><small><strong>Acteurs&nbsp;:</strong> {{ slide.metas_dict.actors }}</small></p>
+              <p><small><strong>Lieux&nbsp;:</strong> {{ slide.metas_dict.places }}</small></p>
           </div>
           </div>
       </slide>
--- a/client/app/slideshow/slideshow_controller.js	Mon Oct 06 17:36:47 2014 +0200
+++ b/client/app/slideshow/slideshow_controller.js	Mon Oct 06 22:52:30 2014 +0200
@@ -9,19 +9,25 @@
           controller: 'slideshowCtrl'
         });
     })
-    .service('slideshowApi', function($resource, context) {
+    /*.service('slideshowApi', function($resource, context) {
       console.log('slideshow 5',this);
       this.slideshow = $resource(context.urls.slideshowUrl);
-    })
-    .service('slideshowModel', function(slideshowApi) {
+    })*/
+    .service('slideshowModel', function(searchApi) {
       console.log('slideshow 6',this);
-      this.slideshow = slideshowApi.slideshow.get();
+      /*this.slideshow = function(myVarForData){
+          searchApi.searchResource({q:'stop_email=toto@gmail.com', of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}, myVarForData);
+      };*/
+      this.slideshow = searchApi.searchResource({q:'stop_email=toto@gmail.com', of: 'json', synthesis: 'false', nresults:'50', callback: 'JSON_CALLBACK'}).getJsonp();
+      console.log('slideshow 6-2',this);
     })
     .controller('slideshowCtrl', function($scope, $filter, $location, $routeParams, $timeout, searchApi, slideshowModel){
-      console.log('slideshow 7', $location, $routeParams, searchApi, slideshowModel);
+      //console.log('slideshow 7', $location, $routeParams, searchApi);
+      console.log('slideshow 7');
       $scope.slideshow = slideshowModel.slideshow;
+      
       $scope.iSlide = parseInt($routeParams.iSlide) || 0;
-      console.log('$routeParams',$routeParams);
+      //console.log('$routeParams',$routeParams);
       if(typeof $routeParams.searched !== 'undefined'){
           var a = $routeParams.searched.split(',');
           var q = a[0], i = parseInt(a[1]);
@@ -44,17 +50,17 @@
           }
       }
       $timeout(function(){
-          if($scope.iSlide>=0 && $scope.iSlide<$scope.slideshow.images.length){
-              $scope.slideshow.images[$scope.iSlide].active = true;
+          if($scope.iSlide>=0 && $scope.iSlide<$scope.slideshow.hits.length){
+              $scope.slideshow.hits[$scope.iSlide].active = true;
               var l = $location.path();
               if(l.substr(0,16)==='/slideshow/edit/'){
-                  $scope.slideshow.images[$scope.iSlide].editMode = true;
+                  $scope.slideshow.hits[$scope.iSlide].editMode = true;
               }
           }
-      }, 200);
-
+      }, 500);
+      
       $scope.save = function(){
-          console.log('8 call save POST',$scope.slideshow);
+          //console.log('8 call save POST',$scope.slideshow);
           $scope.slideshow
           .$save()
           .then(