Component url to uuid migration
This commit is contained in:
@@ -84,7 +84,7 @@ angular.module('app')
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
syncManager.setEventHandler((syncEvent, data) => {
|
syncManager.addEventHandler((syncEvent, data) => {
|
||||||
$rootScope.$broadcast(syncEvent, data || {});
|
$rootScope.$broadcast(syncEvent, data || {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ class ComponentView {
|
|||||||
offlineRestricted = component.offlineOnly && !isDesktopApplication();
|
offlineRestricted = component.offlineOnly && !isDesktopApplication();
|
||||||
|
|
||||||
urlError =
|
urlError =
|
||||||
(!isDesktopApplication() && (!component.url && !component.hosted_url))
|
(!isDesktopApplication() && (!component.hasValidHostedUrl()))
|
||||||
||
|
||
|
||||||
(isDesktopApplication() && (!component.local_url && !component.url && !component.hosted_url))
|
(isDesktopApplication() && (!component.local_url && !component.hasValidHostedUrl()))
|
||||||
|
|
||||||
expired = component.valid_until && component.valid_until <= new Date();
|
expired = component.valid_until && component.valid_until <= new Date();
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ class ComponentView {
|
|||||||
|
|
||||||
$scope.getUrl = function() {
|
$scope.getUrl = function() {
|
||||||
var url = componentManager.urlForComponent($scope.component);
|
var url = componentManager.urlForComponent($scope.component);
|
||||||
$scope.component.runningLocally = (url !== $scope.component.url) && url !== ($scope.component.hosted_url);
|
$scope.component.runningLocally = (url == $scope.component.local_url);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/* This domain will be used to save context item client data */
|
|
||||||
let ClientDataDomain = "org.standardnotes.sn.components";
|
|
||||||
|
|
||||||
class ComponentManager {
|
class ComponentManager {
|
||||||
|
|
||||||
constructor($rootScope, modelManager, syncManager, desktopManager, nativeExtManager, $timeout, $compile) {
|
constructor($rootScope, modelManager, syncManager, desktopManager, nativeExtManager, $timeout, $compile) {
|
||||||
|
/* This domain will be used to save context item client data */
|
||||||
|
ComponentManager.ClientDataDomain = "org.standardnotes.sn.components";
|
||||||
|
|
||||||
this.$compile = $compile;
|
this.$compile = $compile;
|
||||||
this.$rootScope = $rootScope;
|
this.$rootScope = $rootScope;
|
||||||
this.modelManager = modelManager;
|
this.modelManager = modelManager;
|
||||||
@@ -189,8 +190,7 @@ class ComponentManager {
|
|||||||
jsonForItem(item, component, source) {
|
jsonForItem(item, component, source) {
|
||||||
var params = {uuid: item.uuid, content_type: item.content_type, created_at: item.created_at, updated_at: item.updated_at, deleted: item.deleted};
|
var params = {uuid: item.uuid, content_type: item.content_type, created_at: item.created_at, updated_at: item.updated_at, deleted: item.deleted};
|
||||||
params.content = item.createContentJSONFromProperties();
|
params.content = item.createContentJSONFromProperties();
|
||||||
/* Legacy is using component.url key, so if it's present, use it, otherwise use uuid */
|
params.clientData = item.getDomainDataItem(component.getClientDataKey(), ComponentManager.ClientDataDomain) || {};
|
||||||
params.clientData = item.getDomainDataItem(component.url || component.uuid, ClientDataDomain) || {};
|
|
||||||
|
|
||||||
/* This means the this function is being triggered through a remote Saving response, which should not update
|
/* This means the this function is being triggered through a remote Saving response, which should not update
|
||||||
actual local content values. The reason is, Save responses may be delayed, and a user may have changed some values
|
actual local content values. The reason is, Save responses may be delayed, and a user may have changed some values
|
||||||
@@ -268,13 +268,13 @@ class ComponentManager {
|
|||||||
if(component.offlineOnly || (isDesktopApplication() && component.local_url)) {
|
if(component.offlineOnly || (isDesktopApplication() && component.local_url)) {
|
||||||
return component.local_url && component.local_url.replace("sn://", offlinePrefix + this.desktopManager.getApplicationDataPath() + "/");
|
return component.local_url && component.local_url.replace("sn://", offlinePrefix + this.desktopManager.getApplicationDataPath() + "/");
|
||||||
} else {
|
} else {
|
||||||
return component.hosted_url || component.url;
|
return component.hosted_url || component.legacy_url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentForUrl(url) {
|
componentForUrl(url) {
|
||||||
return this.components.filter(function(component){
|
return this.components.filter(function(component){
|
||||||
return component.url === url || component.hosted_url === url;
|
return component.hosted_url === url || component.legacy_url === url;
|
||||||
})[0];
|
})[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ class ComponentManager {
|
|||||||
var responseItem = _.find(responseItems, {uuid: item.uuid});
|
var responseItem = _.find(responseItems, {uuid: item.uuid});
|
||||||
_.merge(item.content, responseItem.content);
|
_.merge(item.content, responseItem.content);
|
||||||
if(responseItem.clientData) {
|
if(responseItem.clientData) {
|
||||||
item.setDomainDataItem(component.url || component.uuid, responseItem.clientData, ClientDataDomain);
|
item.setDomainDataItem(component.getClientDataKey(), responseItem.clientData, ComponentManager.ClientDataDomain);
|
||||||
}
|
}
|
||||||
item.setDirty(true);
|
item.setDirty(true);
|
||||||
}
|
}
|
||||||
@@ -505,7 +505,7 @@ class ComponentManager {
|
|||||||
for(let responseItem of responseItems) {
|
for(let responseItem of responseItems) {
|
||||||
var item = this.modelManager.createItem(responseItem);
|
var item = this.modelManager.createItem(responseItem);
|
||||||
if(responseItem.clientData) {
|
if(responseItem.clientData) {
|
||||||
item.setDomainDataItem(component.url || component.uuid, responseItem.clientData, ClientDataDomain);
|
item.setDomainDataItem(getClientDataKey(), responseItem.clientData, ComponentManager.ClientDataDomain);
|
||||||
}
|
}
|
||||||
this.modelManager.addItem(item);
|
this.modelManager.addItem(item);
|
||||||
this.modelManager.resolveReferencesForItem(item, true);
|
this.modelManager.resolveReferencesForItem(item, true);
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
class MigrationManager {
|
class MigrationManager extends SFMigrationManager {
|
||||||
|
|
||||||
constructor($rootScope, modelManager, syncManager, componentManager) {
|
constructor($rootScope, modelManager, syncManager, componentManager, storageManager) {
|
||||||
this.$rootScope = $rootScope;
|
super(modelManager, syncManager, storageManager);
|
||||||
this.modelManager = modelManager;
|
|
||||||
this.syncManager = syncManager;
|
|
||||||
this.componentManager = componentManager;
|
this.componentManager = componentManager;
|
||||||
|
}
|
||||||
|
|
||||||
this.migrators = [];
|
registeredMigrations() {
|
||||||
|
return [
|
||||||
this.addEditorToComponentMigrator();
|
this.editorToComponentMigration(),
|
||||||
|
this.componentUrlToHostedUrl()
|
||||||
this.modelManager.addItemSyncObserver("migration-manager", "*", (allItems, validItems, deletedItems) => {
|
];
|
||||||
for(var migrator of this.migrators) {
|
|
||||||
var items = allItems.filter((item) => {return item.content_type == migrator.content_type});
|
|
||||||
if(items.length > 0) {
|
|
||||||
migrator.handler(items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -25,10 +17,10 @@ class MigrationManager {
|
|||||||
convert to using the new component API.
|
convert to using the new component API.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addEditorToComponentMigrator() {
|
editorToComponentMigration() {
|
||||||
this.migrators.push({
|
return {
|
||||||
|
name: "editor-to-component",
|
||||||
content_type: "SN|Editor",
|
content_type: "SN|Editor",
|
||||||
|
|
||||||
handler: (editors) => {
|
handler: (editors) => {
|
||||||
// Convert editors to components
|
// Convert editors to components
|
||||||
for(var editor of editors) {
|
for(var editor of editors) {
|
||||||
@@ -54,10 +46,36 @@ class MigrationManager {
|
|||||||
|
|
||||||
this.syncManager.sync();
|
this.syncManager.sync();
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Migrate component.url fields to component.hosted_url. This involves rewriting any note data that relied on the
|
||||||
|
component.url value to store clientData, such as the CodeEditor, which stores the programming language for the note
|
||||||
|
in the note's clientData[component.url]. We want to rewrite any matching items to transfer that clientData into
|
||||||
|
clientData[component.uuid].
|
||||||
|
Created: July 6, 2018
|
||||||
|
*/
|
||||||
|
componentUrlToHostedUrl() {
|
||||||
|
return {
|
||||||
|
name: "component-url-to-hosted-url",
|
||||||
|
content_type: "SN|Component",
|
||||||
|
handler: (components) => {
|
||||||
|
var notes = this.modelManager.validItemsForContentType("Note");
|
||||||
|
for(var note of notes) {
|
||||||
|
for(var component of components) {
|
||||||
|
var clientData = note.getDomainDataItem(component.hosted_url, ComponentManager.ClientDataDomain);
|
||||||
|
if(clientData) {
|
||||||
|
note.setDomainDataItem(component.uuid, clientData, ComponentManager.ClientDataDomain);
|
||||||
|
note.setDomainDataItem(component.hosted_url, null, ComponentManager.ClientDataDomain);
|
||||||
|
note.setDirty(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.syncManager.sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('app').service('migrationManager', MigrationManager);
|
angular.module('app').service('migrationManager', MigrationManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user