Skip to content
This repository was archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
updated compiled from web repo, added zip library
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz committed Feb 6, 2017
1 parent 3032df1 commit 6b32728
Show file tree
Hide file tree
Showing 8 changed files with 5,432 additions and 30 deletions.
10 changes: 10 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
console.log(e);
}

// load zip library (for exporting items as zip)
var scriptTag = document.createElement('script');
scriptTag.src = "./js/zip/zip.js";
scriptTag.async = true;
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(scriptTag);
scriptTag.onload = function() {
zip.workerScriptsPath = "js/zip/";
}

</script>

<script src="./js/compiled.js" debug="false"></script>
Expand Down
114 changes: 86 additions & 28 deletions app/js/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -42960,6 +42960,10 @@ var AccountMenu = function () {
return syncManager.serverPassword;
};

$scope.dashboardURL = function () {
return $scope.server + '/dashboard/?server=' + $scope.server + '&id=' + $scope.user.email + '&pw=' + $scope.serverPassword();
};

$scope.submitPasswordChange = function () {
$scope.passwordChangeData.status = "Generating New Keys...";

Expand Down Expand Up @@ -43028,16 +43032,6 @@ var AccountMenu = function () {
$scope.archiveFormData = { encrypted: $scope.user ? true : false };
$scope.user = authManager.user;

$scope.downloadDataArchive = function () {
var link = document.createElement('a');
link.setAttribute('download', 'notes.json');

var ek = $scope.archiveFormData.encrypted ? syncManager.masterKey : null;

link.href = $scope.itemsDataFile(ek);
link.click();
};

$scope.submitImportPassword = function () {
$scope.performImport($scope.importData.data, $scope.importData.password);
};
Expand Down Expand Up @@ -43124,38 +43118,100 @@ var AccountMenu = function () {
Export
*/

$scope.itemsDataFile = function (ek) {
var textFile = null;
var makeTextFile = function (text) {
var data = new Blob([text], { type: 'text/json' });
function loadZip(callback) {
if (window.zip) {
callback();
return;
}

// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}
var scriptTag = document.createElement('script');
scriptTag.src = "/assets/zip/zip.js";
scriptTag.async = false;
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(scriptTag);
scriptTag.onload = function () {
zip.workerScriptsPath = "assets/zip/";
callback();
};
}

textFile = window.URL.createObjectURL(data);
function downloadZippedNotes(notes) {
loadZip(function () {

// returns a URL you can use as a href
return textFile;
}.bind(this);
zip.createWriter(new zip.BlobWriter("application/zip"), function (zipWriter) {

var index = 0;
function nextFile() {
var note = notes[index];
var blob = new Blob([note.text], { type: 'text/plain' });
zipWriter.add(note.title + '-' + note.uuid + '.txt', new zip.BlobReader(blob), function () {
index++;
if (index < notes.length) {
nextFile();
} else {
zipWriter.close(function (blob) {
downloadData(blob, 'Notes Txt Archive - ' + new Date() + '.zip');
zipWriter = null;
});
}
});
}

nextFile();
}, onerror);
});
}

var textFile = null;

function hrefForData(data) {
// If we are replacing a previously generated file we need to
// manually revoke the object URL to avoid memory leaks.
if (textFile !== null) {
window.URL.revokeObjectURL(textFile);
}

textFile = window.URL.createObjectURL(data);

// returns a URL you can use as a href
return textFile;
}

function downloadData(data, fileName) {
var link = document.createElement('a');
link.setAttribute('download', fileName);
link.href = hrefForData(data);
link.click();
}

$scope.downloadDataArchive = function () {
// download in Standard File format
var ek = $scope.archiveFormData.encrypted ? syncManager.masterKey : null;
var data = $scope.itemsData(ek);
downloadData(data, 'SN Archive - ' + new Date() + '.json');

// download as zipped plain text files
if (!ek) {
var notes = modelManager.allItemsMatchingTypes(["Note"]);
downloadZippedNotes(notes);
}
};

$scope.itemsData = function (ek) {
var items = _.map(modelManager.allItemsMatchingTypes(["Tag", "Note"]), function (item) {
var itemParams = new ItemParams(item, ek);
return itemParams.paramsForExportFile();
}.bind(this));

var data = {
items: items
};
var data = { items: items };

if (ek) {
// auth params are only needed when encrypted with a standard file key
data["auth_params"] = authManager.getAuthParams();
}

return makeTextFile(JSON.stringify(data, null, 2 /* pretty print */));
var data = new Blob([JSON.stringify(data, null, 2 /* pretty print */)], { type: 'text/json' });
return data;
};
}]
}]);
Expand Down Expand Up @@ -44612,6 +44668,7 @@ angular.module('app.frontend').service('syncManager', SyncManager);
" <div class='wrap normal mt-1'>{{serverPassword() ? serverPassword() : 'Not available. Sign out then sign back in to compute.'}}</div>\n" +
" </label>\n" +
" </section>\n" +
" <a class='block mt-5' href='{{dashboardURL()}}' target='_blank'>Standard File Dashboard</a>\n" +
" <div class='bold mt-10 blue' delay-hide='true' delay='1000' show='syncStatus.syncOpInProgress'>\n" +
" <div class='spinner inline mr-5 blue'></div>\n" +
" Syncing\n" +
Expand Down Expand Up @@ -44648,6 +44705,7 @@ angular.module('app.frontend').service('syncManager', SyncManager);
" <input ng-model='importData.password' type='text'>\n" +
" <button ng-click='submitImportPassword()'>Decrypt & Import</button>\n" +
" </div>\n" +
" <p class='mt-5' ng-if='user'>Notes are downloaded in the Standard File format, which allows you to re-import back into this app easily. To download as plain text files, choose \"Decrypted\".</p>\n" +
" </div>\n" +
" <div class='spinner mt-10' ng-if='importData.loading'></div>\n" +
" <a class='block mt-25 red' ng-click='destroyLocalData()'>Destroy all local data</a>\n" +
Expand Down Expand Up @@ -45281,7 +45339,7 @@ angular.module('app.frontend').service('syncManager', SyncManager);
" </div>\n" +
" <div class='scrollable'>\n" +
" <div can-load='true' class='infinite-scroll' infinite-scroll='ctrl.paginate()' threshold='200'>\n" +
" <div class='note' ng-class=\"{'selected' : ctrl.selectedNote == note}\" ng-click='ctrl.selectNote(note)' ng-repeat='note in ctrl.tag.notes | limitTo:ctrl.notesToDisplay | filter: ctrl.filterNotes'>\n" +
" <div class='note' ng-class=\"{'selected' : ctrl.selectedNote == note}\" ng-click='ctrl.selectNote(note)' ng-repeat='note in ctrl.tag.notes | filter: ctrl.filterNotes | limitTo:ctrl.notesToDisplay'>\n" +
" <div class='name' ng-if='note.title'>\n" +
" {{note.title}}\n" +
" </div>\n" +
Expand Down
Loading

0 comments on commit 6b32728

Please sign in to comment.