This commit is contained in:
Mo Bitar
2017-12-23 11:25:08 -06:00
parent 2bc52578e0
commit 0c31668625
14 changed files with 186 additions and 32 deletions

View File

@@ -3,12 +3,13 @@ let ClientDataDomain = "org.standardnotes.sn.components";
class ComponentManager {
constructor($rootScope, modelManager, syncManager, themeManager, $timeout, $compile) {
constructor($rootScope, modelManager, syncManager, desktopManager, themeManager, $timeout, $compile) {
this.$compile = $compile;
this.$rootScope = $rootScope;
this.modelManager = modelManager;
this.syncManager = syncManager;
this.themeManager = themeManager;
this.desktopManager = desktopManager;
this.timeout = $timeout;
this.streamObservers = [];
this.contextStreamObservers = [];
@@ -42,6 +43,10 @@ class ComponentManager {
}
var syncedComponents = allItems.filter(function(item){return item.content_type === "SN|Component" });
// Ensure any component in our data is installed by the system
this.desktopManager.syncComponentsInstallation(syncedComponents);
for(var component of syncedComponents) {
var activeComponent = _.find(this.activeComponents, {uuid: component.uuid});
if(component.active && !component.deleted && !activeComponent) {
@@ -191,19 +196,20 @@ class ComponentManager {
/**
Possible Messages:
set-size
stream-items
stream-context-item
save-items
select-item
associate-item
deassociate-item
clear-selection
create-item
delete-items
set-component-data
save-context-client-data
get-context-client-data
set-size
stream-items
stream-context-item
save-items
select-item
associate-item
deassociate-item
clear-selection
create-item
delete-items
set-component-data
save-context-client-data
get-context-client-data
install-local-component
*/
if(message.action === "stream-items") {
@@ -274,6 +280,17 @@ class ComponentManager {
});
}
else if(message.action === "install-local-component") {
console.log("Received install-local-component event");
this.desktopManager.installOfflineComponentFromData(message.data, (response) => {
console.log("componentManager: installed component:", response);
var component = this.modelManager.mapResponseItemsToLocalModels([response], ModelManager.MappingSourceComponentRetrieved)[0];
// Save updated URL
component.setDirty(true);
this.syncManager.sync();
})
}
for(let handler of this.handlers) {
if(handler.areas.includes(component.area)) {
this.timeout(function(){
@@ -585,6 +602,14 @@ class ComponentManager {
component.ignoreEvents = !on;
}
urlForComponent(component) {
if(isDesktopApplication() && component.local && component.url.startsWith("sn://")) {
return component.url.replace("sn://", this.desktopManager.getApplicationDataPath() + "/");
} else {
return component.url;
}
}
iframeForComponent(component) {
for(var frame of document.getElementsByTagName("iframe")) {
var componentId = frame.dataset.componentId;