"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol==="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var _createClass=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(e,r.key,r)}}return function(t,i,r){if(i)e(t.prototype,i);if(r)e(t,r);return t}}();/* @preserve TW-Guard */
/*\

title: $:/plugins/felixhayashi/tiddlymap/js/Fixer
type: application/javascript
module-type: library

@preserve

\*/
/* @preserve TW-Guard */var _utils=require("$:/plugins/felixhayashi/tiddlymap/js/utils");var _utils2=_interopRequireDefault(_utils);var _ViewAbstraction=require("$:/plugins/felixhayashi/tiddlymap/js/ViewAbstraction");var _ViewAbstraction2=_interopRequireDefault(_ViewAbstraction);var _EdgeType=require("$:/plugins/felixhayashi/tiddlymap/js/EdgeType");var _EdgeType2=_interopRequireDefault(_EdgeType);var _NodeType=require("$:/plugins/felixhayashi/tiddlymap/js/NodeType");var _NodeType2=_interopRequireDefault(_NodeType);var _environment=require("$:/plugins/felixhayashi/tiddlymap/js/lib/environment");var env=_interopRequireWildcard(_environment);function _interopRequireWildcard(e){if(e&&e.__esModule){return e}else{var t={};if(e!=null){for(var i in e){if(Object.prototype.hasOwnProperty.call(e,i))t[i]=e[i]}}t.default=e;return t}}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}var Fixer=function(){function e(t,i,r){_classCallCheck(this,e);this.adapter=t;this.logger=i;this.wiki=$tw.wiki;this.glNTy=r}_createClass(e,[{key:"moveEdges",value:function e(t,i){var r=_utils2.default.getTiddlersByPrefix(t);for(var a=0;a<r.length;a++){var u=_utils2.default.getBasename(r[a]);if(u==="__noname__"){u="tmap:unknown"}u=_EdgeType2.default.getInstance(u);if(!u.exists()){u.save()}var n=this.wiki.getTiddlerData(r[a]);for(var s=0;s<n.length;s++){n[s].type=(i?i+":":"")+u.id;this.adapter.insertEdge(n[s])}this.wiki.deleteTiddler(r[a])}}},{key:"executeUpgrade",value:function e(t,i,r){if(!_utils2.default.isLeftVersionGreater(t,i)){return}this.logger("debug","Upgrading data structure to "+t);var a=r();_utils2.default.setEntry(env.ref.sysMeta,"dataStructureState",t);return a}},{key:"fixId",value:function e(){var t=this.wiki.getTiddlerData(env.ref.sysMeta,{});this.executeUpgrade("0.9.2",t.dataStructureState,function(){if(_utils2.default.isLeftVersionGreater("0.9.2",t.originalVersion)){var e="$:/plugins/felixhayashi/tiddlymap/config/sys/user";var i=_utils2.default.getEntry(e,"field.nodeId","tmap.id");_utils2.default.moveFieldValues(i,"tmap.id",true,false)}})}},{key:"fix",value:function e(){var t=this;var i=this.wiki.getTiddlerData(env.ref.sysMeta,{});this.logger("debug","Fixer is started");this.logger("debug","Data-structure currently in use: ",i.dataStructureState);this.executeUpgrade("0.7.0",i.dataStructureState,function(){t.moveEdges("$:/plugins/felixhayashi/tiddlymap/graph/edges",null);var e=env.selector.allViews;var i=_utils2.default.getMatches(e);for(var r=0;r<i.length;r++){var a=new _ViewAbstraction2.default(i[r]);t.moveEdges(a.getRoot()+"/graph/edges",a)}});this.executeUpgrade("0.7.32",i.dataStructureState,function(){if(!_ViewAbstraction2.default.exists("Live View")){return}var e=new _ViewAbstraction2.default("Live View");e.setNodeFilter("[field:title{$:/temp/tmap/currentTiddler}]",true);e.setConfig({"refresh-trigger":null,"refresh-triggers":$tw.utils.stringifyList(["$:/temp/tmap/currentTiddler"])})});this.executeUpgrade("0.9.0",i.dataStructureState,function(){var e=env.ref.visUserConf;var i=_utils2.default.unflatten(t.wiki.getTiddlerData(e,{}));if(_typeof(i.groups)==="object"){var r=_NodeType2.default.getInstance("tmap:neighbour");r.setStyle(i.groups["neighbours"]);r.save();delete i.groups;t.wiki.setTiddlerData(e,i)}});this.fixId();this.executeUpgrade("0.9.16",i.dataStructureState,function(){for(var e=t.glNTy.length;e--;){t.glNTy[e].save(null,true)}});this.executeUpgrade("0.10.3",i.dataStructureState,function(){var e=env.ref.liveTab;if(_utils2.default.getTiddler(e).hasTag("$:/tags/SideBar")){this.wiki.deleteTiddler(e);_utils2.default.setField(e,"tags","$:/tags/SideBar")}});this.executeUpgrade("0.11.0",i.dataStructureState,function(){var e=_utils2.default.getMatches(env.selector.allViews);for(var t=e.length;t--;){var i=new _ViewAbstraction2.default(e[t]);var r=i.getEdgeTypeFilter("raw");var a="edge_type_namespace";i.setConfig(a,i.getConfig(a));var u=env.filter.defaultEdgeTypeFilter;if(r){var n=env.path.edgeTypes;r=_utils2.default.replaceAll(r,"",[n,n+"/","[prefix["+n+"]]","[prefix["+n+"/]]",["[suffix[tw-body:link]]","[[tw-body:link]]"],["[suffix[tw-list:tags]]","[[tw-list:tags]]"],["[suffix[tw-list:list]]","[[tw-body:list]]"],["[suffix[tmap:unknown]]","[[tmap:unknown]]"],["[suffix[unknown]]","[[tmap:unknown]]"]]);u="-[prefix[_]] "+r}i.setEdgeTypeFilter(u)}})}}]);return e}();exports.default=Fixer;
//# sourceMappingURL=./maps/felixhayashi/tiddlymap/js/services/Fixer.js.map
