'use strict';

function threatmodellocator() {

    var service = {
        getModelLocation: getModelLocation,
        getModelPath: getModelPath,
        getModelPathFromRouteParams: getModelPathFromRouteParams,
        willMoveModel: willMoveModel,
        newModelLocation: '/threatmodel/new'
    };

    return service;

    //gets a file path from a uri encoded value
    //repeatedely decode until it looks like an unencoded value
    function getModelLocation(params) {

        var result = params.location;

        while (checkEncoded(result)) {
            result = atob(result);
        }

        return result;
    }

    //gets a url path from a file path
    //encode it unless it already looks encoded
    function getModelPath(location) {

        var result = location;

        if (!checkEncoded(result)) {
            result = btoa(result);
        }

        return result;
    }

    //get a url path from a route params object
    //encode it unless it already looks encoded
    function getModelPathFromRouteParams(params) {
        var result = params.location;

        if (!checkEncoded(result)) {
            result = btoa(result);
        }

        return result;
    }

    function willMoveModel() {
        return false;
    }

    function checkEncoded(value) {
        var pattern = /\\|\//i;
        return !pattern.test(value);
    }
}

module.exports = threatmodellocator;
@@ -353,11 +353,14 @@
 m a 
-uri
+base64
  enc
@@ -430,24 +430,42 @@
 coded value%0A
+    //ignore demo%0A
     function
@@ -524,32 +524,68 @@
 rams.location;%0A%0A
+        if (result != 'demo') %7B%0A    
         while (c
@@ -599,32 +599,36 @@
 oded(result)) %7B%0A
+    
             resu
@@ -638,32 +638,46 @@
 = atob(result);%0A
+            %7D%0A
         %7D%0A%0A     
@@ -742,24 +742,31 @@
  path%0A    //
+base64 
 encode it un
@@ -787,32 +787,50 @@
 y looks encoded%0A
+    //ignore demo%0A
     function get
@@ -876,32 +876,68 @@
 lt = location;%0A%0A
+        if (result != 'demo') %7B%0A    
         if (!che
@@ -949,32 +949,36 @@
 oded(result)) %7B%0A
+    
             resu
@@ -1008,331 +1008,150 @@
     
-%7D%0A%0A
     
+%7D%0A
     
-return result;%0A    %7D%0A%0A    //get a url path from a route params object%0A    //encode it unless it already looks encoded%0A    function getModelPathFromRouteParams(params) %7B%0A        var result = params.location;%0A%0A        if (!checkEncoded(result)) %7B%0A            result = btoa(result);%0A        %7D%0A%0A        return result
+    %7D%0A%0A        return result;%0A    %7D%0A%0A    function getModelPathFromRouteParams(params) %7B%0A        return getModelPath(params.location)
 ;%0A  

fix load of demo model