Extracted componentManager into snjs

This commit is contained in:
Mo Bitar
2019-04-30 19:38:29 -05:00
parent 5901f4a623
commit 43c9f02bfe
12 changed files with 2170 additions and 1857 deletions

View File

@@ -55,11 +55,6 @@ Array.prototype.containsPrimitiveSubset = function(array) {
return !array.some(val => this.indexOf(val) === -1);
}
/* Use with numbers and strings, not objects */
Array.prototype.containsObjectSubset = function(array) {
return !array.some(val => !_.find(this, val));
}
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {

View File

@@ -111,15 +111,16 @@ class ComponentView {
}
$timeout.cancel($scope.loadTimeout);
componentManager.registerComponentWindow(component, iframe.contentWindow);
componentManager.registerComponentWindow(component, iframe.contentWindow).then(() => {
// Add small timeout to, as $scope.loading controls loading overlay,
// which is used to avoid flicker when enabling extensions while having an enabled theme
// we don't use ng-show because it causes problems with rendering iframes after timeout, for some reason.
$timeout(() => {
$scope.loading = false;
$scope.issueLoading = desktopError; /* Typically we'd just set this to false at this point, but we now account for desktopError */
}, 7)
})
// Add small timeout to, as $scope.loading controls loading overlay,
// which is used to avoid flicker when enabling extensions while having an enabled theme
// we don't use ng-show because it causes problems with rendering iframes after timeout, for some reason.
$timeout(() => {
$scope.loading = false;
$scope.issueLoading = desktopError; /* Typically we'd just set this to false at this point, but we now account for desktopError */
}, 7)
};
}
}
@@ -158,9 +159,8 @@ class ComponentView {
// console.log("Reloading component", $scope.component);
// force iFrame to deinit, allows new one to be created
$scope.componentValid = false;
componentManager.reloadComponent($scope.component).then(() => {
$scope.reloadStatus();
});
componentManager.reloadComponent($scope.component);
$scope.reloadStatus();
}
$scope.reloadStatus = function(doManualReload = true) {

View File

@@ -6,7 +6,7 @@ class PermissionsModal {
this.scope = {
show: "=",
component: "=",
permissions: "=",
permissionsString: "=",
callback: "="
};
}
@@ -31,68 +31,6 @@ class PermissionsModal {
controller($scope, modelManager) {
'ngInject';
$scope.permissionsString = function() {
var finalString = "";
let permissionsCount = $scope.permissions.length;
let addSeparator = (index, length) => {
if(index > 0) {
if(index == length - 1) {
if(length == 2) {
return " and ";
} else {
return ", and "
}
} else {
return ", ";
}
}
return "";
}
$scope.permissions.forEach((permission, index) => {
if(permission.name === "stream-items") {
var types = permission.content_types.map(function(type){
var desc = modelManager.humanReadableDisplayForContentType(type);
if(desc) {
return desc + "s";
} else {
return "items of type " + type;
}
})
var typesString = "";
for(var i = 0;i < types.length;i++) {
var type = types[i];
typesString += addSeparator(i, types.length + permissionsCount - index - 1);
typesString += type;
}
finalString += addSeparator(index, permissionsCount);
finalString += typesString;
if(types.length >= 2 && index < permissionsCount - 1) {
// If you have a list of types, and still an additional root-level permission coming up, add a comma
finalString += ", ";
}
} else if(permission.name === "stream-context-item") {
var mapping = {
"editor-stack" : "working note",
"note-tags" : "working note",
"editor-editor": "working note"
}
finalString += addSeparator(index, permissionsCount, true);
finalString += mapping[$scope.component.area];
}
})
return finalString + ".";
}
}
}

File diff suppressed because it is too large Load Diff