src/js/serializers/ldt-serializer.js
changeset 1072 ac1eacb3aa33
parent 1069 2409cb4cebaf
equal deleted inserted replaced
1071:02c04d2c8fd8 1072:ac1eacb3aa33
     1 /* Start ldt-serializer.js */
     1 /* Start ldt-serializer.js */
       
     2 import _ from "lodash";
     2 
     3 
     3 if (typeof IriSP.serializers === "undefined") {
     4 const ldt = function(IriSP) { return {
     4     IriSP.serializers = {};
       
     5 }
       
     6 
       
     7 IriSP.serializers.ldt = {
       
     8     types :  {
     5     types :  {
     9         media : {
     6         media : {
    10             serialized_name : "medias",
     7             serialized_name : "medias",
    11             deserializer : function(_data, _source) {
     8             deserializer : function(_data, _source) {
    12                 var _res = new IriSP.Model.Media(_data.id, _source);
     9                 var _res = new IriSP.Model.Media(_data.id, _source);
   149                     _res.color = '#' + _c;
   146                     _res.color = '#' + _c;
   150                 }
   147                 }
   151                 _res.content = _data.content;
   148                 _res.content = _data.content;
   152                 _res.setMedia(_data.media);
   149                 _res.setMedia(_data.media);
   153                 _res.setAnnotationType(_data.meta["id-ref"]);
   150                 _res.setAnnotationType(_data.meta["id-ref"]);
   154                 _res.setTags(IriSP._(_data.tags).pluck("id-ref"));
   151                 _res.setTags(_(_data.tags).map("id-ref"));
   155                 _res.keywords = _res.getTagTexts();
   152                 _res.keywords = _res.getTagTexts();
   156                 _res.setBegin(_data.begin);
   153                 _res.setBegin(_data.begin);
   157                 _res.setEnd(_data.end);
   154                 _res.setEnd(_data.end);
   158                 _res.creator = _data.meta["dc:creator"] || "";
   155                 _res.creator = _data.meta["dc:creator"] || "";
   159                 _res.project = _data.meta.project || "";
   156                 _res.project = _data.meta.project || "";
   169                 var _color = parseInt(_data.color.replace(/^#/,''),16).toString();
   166                 var _color = parseInt(_data.color.replace(/^#/,''),16).toString();
   170                 var _res = {
   167                 var _res = {
   171                     id : _data.id,
   168                     id : _data.id,
   172                     begin : _data.begin.milliseconds,
   169                     begin : _data.begin.milliseconds,
   173                     end : _data.end.milliseconds,
   170                     end : _data.end.milliseconds,
   174                     content : IriSP._.defaults(
   171                     content : _.defaults(
   175                         {},
   172                         {},
   176                         {
   173                         {
   177                             title : _data.title,
   174                             title : _data.title,
   178                             description : _data.description,
   175                             description : _data.description,
   179                         audio : _data.audio,
   176                         audio : _data.audio,
   197                         "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator
   194                         "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator
   198 //                        project : _source.projectId
   195 //                        project : _source.projectId
   199                     }
   196                     }
   200                 };
   197                 };
   201                 if (_source.regenerateTags) {
   198                 if (_source.regenerateTags) {
   202                     _res.tags = IriSP._(_data.keywords).map(function(_kw) {
   199                     _res.tags = _(_data.keywords).map(function(_kw) {
   203                         return {
   200                         return {
   204                             "id-ref": _source.__keywords[_kw.toLowerCase()].id
   201                             "id-ref": _source.__keywords[_kw.toLowerCase()].id
   205                         };
   202                         };
   206                     });
   203                     });
   207                 } else {
   204                 } else {
   208                     _res.tags = IriSP._(_data.tag.id).map(function(_id) {
   205                     _res.tags = _(_data.tag.id).map(function(_id) {
   209                        return {
   206                        return {
   210                            "id-ref" : _id
   207                            "id-ref" : _id
   211                        };
   208                        };
   212                     });
   209                     });
   213                 }
   210                 }
   274             },
   271             },
   275             _this = this;
   272             _this = this;
   276         if (_source.regenerateTags) {
   273         if (_source.regenerateTags) {
   277             _source.__keywords = {};
   274             _source.__keywords = {};
   278             _source.getAnnotations().forEach(function(a) {
   275             _source.getAnnotations().forEach(function(a) {
   279                 IriSP._(a.keywords).each(function(kw) {
   276                 _(a.keywords).each(function(kw) {
   280                     var lkw = kw.toLowerCase();
   277                     var lkw = kw.toLowerCase();
   281                     if (typeof _source.__keywords[lkw] === "undefined") {
   278                     if (typeof _source.__keywords[lkw] === "undefined") {
   282                         _source.__keywords[lkw] = {
   279                         _source.__keywords[lkw] = {
   283                             id: IriSP.Model.getUID(),
   280                             id: IriSP.Model.getUID(),
   284                             title: kw,
   281                             title: kw,
   285                             regenerated: true
   282                             regenerated: true
   286                         };
   283                         };
   287                     }
   284                     }
   288                 });
   285                 });
   289             });
   286             });
   290             IriSP._(_source.__keywords).each(function(kw) {
   287             _(_source.__keywords).each(function(kw) {
   291                 _this.types.tag.serializer(kw, _source, _res);
   288                 _this.types.tag.serializer(kw, _source, _res);
   292             });
   289             });
   293         }
   290         }
   294         _source.forEach(function(_list, _typename) {
   291         _source.forEach(function(_list, _typename) {
   295             if (typeof _this.types[_typename] !== "undefined") {
   292             if (typeof _this.types[_typename] !== "undefined") {
   302     },
   299     },
   303     deSerialize : function(_data, _source) {
   300     deSerialize : function(_data, _source) {
   304         if (typeof _data !== "object" || _data === null) {
   301         if (typeof _data !== "object" || _data === null) {
   305             return;
   302             return;
   306         }
   303         }
   307         IriSP._(this.types).forEach(function(_type, _typename) {
   304         _(this.types).forEach(function(_type, _typename) {
   308             var _listdata = _data[_type.serialized_name],
   305             var _listdata = _data[_type.serialized_name],
   309                 _list = new IriSP.Model.List(_source.directory);
   306                 _list = new IriSP.Model.List(_source.directory);
   310             if (typeof _listdata !== "undefined" && _listdata !== null) {
   307             if (typeof _listdata !== "undefined" && _listdata !== null) {
   311                 if (_listdata.hasOwnProperty("length")) {
   308                 if (_listdata.hasOwnProperty("length")) {
   312                     var _l = _listdata.length;
   309                     var _l = _listdata.length;
   337         
   334         
   338         if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") {
   335         if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") {
   339             _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]);
   336             _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]);
   340         }
   337         }
   341     }
   338     }
   342 };
   339 }};
       
   340 
       
   341 export default ldt;
   343 
   342 
   344 /* End of LDT Platform Serializer */
   343 /* End of LDT Platform Serializer */