Migrated ko.computed to ko.pureComputed where it made sense
This commit is contained in:
parent
caaf1d229c
commit
7f1394a8d6
17 changed files with 61 additions and 61 deletions
|
|
@ -90,7 +90,7 @@ $(function() {
|
|||
self.workingDialog = undefined;
|
||||
self.workingOutput = undefined;
|
||||
|
||||
self.enableManagement = ko.computed(function() {
|
||||
self.enableManagement = ko.pureComputed(function() {
|
||||
return !self.printerState.isPrinting();
|
||||
});
|
||||
|
||||
|
|
@ -110,22 +110,22 @@ $(function() {
|
|||
return self.enableManagement() && self.pipAvailable() && self.isCompatible(data);
|
||||
};
|
||||
|
||||
self.invalidUrl = ko.computed(function() {
|
||||
self.invalidUrl = ko.pureComputed(function() {
|
||||
var url = self.installUrl();
|
||||
return url !== undefined && url.trim() != "" && !(_.startsWith(url.toLocaleLowerCase(), "http://") || _.startsWith(url.toLocaleLowerCase(), "https://"));
|
||||
});
|
||||
|
||||
self.enableUrlInstall = ko.computed(function() {
|
||||
self.enableUrlInstall = ko.pureComputed(function() {
|
||||
var url = self.installUrl();
|
||||
return self.enableManagement() && self.pipAvailable() && url !== undefined && url.trim() != "" && !self.invalidUrl();
|
||||
});
|
||||
|
||||
self.invalidArchive = ko.computed(function() {
|
||||
self.invalidArchive = ko.pureComputed(function() {
|
||||
var name = self.uploadFilename();
|
||||
return name !== undefined && !(_.endsWith(name.toLocaleLowerCase(), ".zip") || _.endsWith(name.toLocaleLowerCase(), ".tar.gz") || _.endsWith(name.toLocaleLowerCase(), ".tgz") || _.endsWith(name.toLocaleLowerCase(), ".tar"));
|
||||
});
|
||||
|
||||
self.enableArchiveInstall = ko.computed(function() {
|
||||
self.enableArchiveInstall = ko.pureComputed(function() {
|
||||
var name = self.uploadFilename();
|
||||
return self.enableManagement() && self.pipAvailable() && name !== undefined && name.trim() != "" && !self.invalidArchive();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ $(function() {
|
|||
self.color = parameters[0].appearance_color;
|
||||
self.colorTransparent = parameters[0].appearance_colorTransparent;
|
||||
|
||||
self.brand = ko.computed(function() {
|
||||
self.brand = ko.pureComputed(function() {
|
||||
if (self.name())
|
||||
return gettext("OctoPrint") + ": " + self.name();
|
||||
else
|
||||
return gettext("OctoPrint");
|
||||
});
|
||||
|
||||
self.title = ko.computed(function() {
|
||||
self.title = ko.pureComputed(function() {
|
||||
if (self.name())
|
||||
return self.name() + " [" + gettext("OctoPrint") + "]";
|
||||
else
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ $(function() {
|
|||
self.isReady = ko.observable(undefined);
|
||||
self.isLoading = ko.observable(undefined);
|
||||
|
||||
self.buttonText = ko.computed(function() {
|
||||
self.buttonText = ko.pureComputed(function() {
|
||||
if (self.isErrorOrClosed())
|
||||
return gettext("Connect");
|
||||
else
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ $(function() {
|
|||
|
||||
self.keycontrolActive = ko.observable(false);
|
||||
self.keycontrolHelpActive = ko.observable(false);
|
||||
self.keycontrolPossible = ko.computed(function () {
|
||||
self.keycontrolPossible = ko.pureComputed(function () {
|
||||
return self.isOperational() && !self.isPrinting() && self.loginState.isUser() && !$.browser.mobile;
|
||||
});
|
||||
self.showKeycontrols = ko.computed(function () {
|
||||
self.showKeycontrols = ko.pureComputed(function () {
|
||||
return self.keycontrolActive() && self.keycontrolPossible();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -23,26 +23,26 @@ $(function() {
|
|||
|
||||
self.freeSpace = ko.observable(undefined);
|
||||
self.totalSpace = ko.observable(undefined);
|
||||
self.freeSpaceString = ko.computed(function() {
|
||||
self.freeSpaceString = ko.pureComputed(function() {
|
||||
if (!self.freeSpace())
|
||||
return "-";
|
||||
return formatSize(self.freeSpace());
|
||||
});
|
||||
self.totalSpaceString = ko.computed(function() {
|
||||
self.totalSpaceString = ko.pureComputed(function() {
|
||||
if (!self.totalSpace())
|
||||
return "-";
|
||||
return formatSize(self.totalSpace());
|
||||
});
|
||||
|
||||
self.diskusageWarning = ko.computed(function() {
|
||||
self.diskusageWarning = ko.pureComputed(function() {
|
||||
return self.freeSpace() != undefined
|
||||
&& self.freeSpace() < self.settingsViewModel.server_diskspace_warning();
|
||||
});
|
||||
self.diskusageCritical = ko.computed(function() {
|
||||
self.diskusageCritical = ko.pureComputed(function() {
|
||||
return self.freeSpace() != undefined
|
||||
&& self.freeSpace() < self.settingsViewModel.server_diskspace_critical();
|
||||
});
|
||||
self.diskusageString = ko.computed(function() {
|
||||
self.diskusageString = ko.pureComputed(function() {
|
||||
if (self.diskusageCritical()) {
|
||||
return gettext("Your available free disk space is critically low.");
|
||||
} else if (self.diskusageWarning()) {
|
||||
|
|
@ -104,11 +104,11 @@ $(function() {
|
|||
0
|
||||
);
|
||||
|
||||
self.isLoadActionPossible = ko.computed(function() {
|
||||
self.isLoadActionPossible = ko.pureComputed(function() {
|
||||
return self.loginState.isUser() && !self.isPrinting() && !self.isPaused() && !self.isLoading();
|
||||
});
|
||||
|
||||
self.isLoadAndPrintActionPossible = ko.computed(function() {
|
||||
self.isLoadAndPrintActionPossible = ko.pureComputed(function() {
|
||||
return self.loginState.isUser() && self.isOperational() && self.isLoadActionPossible();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -6,19 +6,19 @@ $(function() {
|
|||
self.password = ko.observable(undefined);
|
||||
self.confirmedPassword = ko.observable(undefined);
|
||||
|
||||
self.passwordMismatch = ko.computed(function() {
|
||||
self.passwordMismatch = ko.pureComputed(function() {
|
||||
return self.password() != self.confirmedPassword();
|
||||
});
|
||||
|
||||
self.validUsername = ko.computed(function() {
|
||||
self.validUsername = ko.pureComputed(function() {
|
||||
return self.username() && self.username().trim() != "";
|
||||
});
|
||||
|
||||
self.validPassword = ko.computed(function() {
|
||||
self.validPassword = ko.pureComputed(function() {
|
||||
return self.password() && self.password().trim() != "";
|
||||
});
|
||||
|
||||
self.validData = ko.computed(function() {
|
||||
self.validData = ko.pureComputed(function() {
|
||||
return !self.passwordMismatch() && self.validUsername() && self.validPassword();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ $(function() {
|
|||
|
||||
self.ui_progress_percentage = ko.observable();
|
||||
self.ui_progress_type = ko.observable();
|
||||
self.ui_progress_text = ko.computed(function() {
|
||||
self.ui_progress_text = ko.pureComputed(function() {
|
||||
var text = "";
|
||||
switch (self.ui_progress_type()) {
|
||||
case "loading": {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ $(function() {
|
|||
|
||||
self.currentUser = ko.observable(undefined);
|
||||
|
||||
self.userMenuText = ko.computed(function() {
|
||||
self.userMenuText = ko.pureComputed(function() {
|
||||
if (self.loggedIn()) {
|
||||
return self.username();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ $(function() {
|
|||
|
||||
self.systemActions = self.settings.system_actions;
|
||||
|
||||
self.appearanceClasses = ko.computed(function() {
|
||||
self.appearanceClasses = ko.pureComputed(function() {
|
||||
var classes = self.appearance.color();
|
||||
if (self.appearance.colorTransparent()) {
|
||||
classes += " transparent";
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ $(function() {
|
|||
{key: "black", name: gettext("black")}
|
||||
]);
|
||||
|
||||
self.availableOrigins = ko.computed(function() {
|
||||
self.availableOrigins = ko.pureComputed(function() {
|
||||
var formFactor = self.editorVolumeFormFactor();
|
||||
|
||||
var possibleOrigins = {
|
||||
|
|
@ -123,7 +123,7 @@ $(function() {
|
|||
return result;
|
||||
});
|
||||
|
||||
self.koEditorExtruderOffsets = ko.computed(function() {
|
||||
self.koEditorExtruderOffsets = ko.pureComputed(function() {
|
||||
var extruderOffsets = self.editorExtruderOffsets();
|
||||
var numExtruders = self.editorExtruders();
|
||||
if (!numExtruders) {
|
||||
|
|
@ -144,11 +144,11 @@ $(function() {
|
|||
return extruderOffsets.slice(0, numExtruders - 1);
|
||||
});
|
||||
|
||||
self.editorNameInvalid = ko.computed(function() {
|
||||
self.editorNameInvalid = ko.pureComputed(function() {
|
||||
return !self.editorName();
|
||||
});
|
||||
|
||||
self.editorIdentifierInvalid = ko.computed(function() {
|
||||
self.editorIdentifierInvalid = ko.pureComputed(function() {
|
||||
var identifier = self.editorIdentifier();
|
||||
var placeholder = self.editorIdentifierPlaceholder();
|
||||
var data = identifier;
|
||||
|
|
@ -162,7 +162,7 @@ $(function() {
|
|||
return !data || !validCharacters || (self.editorNew() && existingProfile != undefined);
|
||||
});
|
||||
|
||||
self.editorIdentifierInvalidText = ko.computed(function() {
|
||||
self.editorIdentifierInvalidText = ko.pureComputed(function() {
|
||||
if (!self.editorIdentifierInvalid()) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ $(function() {
|
|||
}
|
||||
});
|
||||
|
||||
self.enableEditorSubmitButton = ko.computed(function() {
|
||||
self.enableEditorSubmitButton = ko.pureComputed(function() {
|
||||
return !self.editorNameInvalid() && !self.editorIdentifierInvalid() && !self.requestInProgress();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ $(function() {
|
|||
self.isLoading = ko.observable(undefined);
|
||||
self.isSdReady = ko.observable(undefined);
|
||||
|
||||
self.enablePrint = ko.computed(function() {
|
||||
self.enablePrint = ko.pureComputed(function() {
|
||||
return self.isOperational() && self.isReady() && !self.isPrinting() && self.loginState.isUser() && self.filename() != undefined;
|
||||
});
|
||||
self.enablePause = ko.computed(function() {
|
||||
self.enablePause = ko.pureComputed(function() {
|
||||
return self.isOperational() && (self.isPrinting() || self.isPaused()) && self.loginState.isUser();
|
||||
});
|
||||
self.enableCancel = ko.computed(function() {
|
||||
self.enableCancel = ko.pureComputed(function() {
|
||||
return self.isOperational() && (self.isPrinting() || self.isPaused()) && self.loginState.isUser();
|
||||
});
|
||||
|
||||
|
|
@ -49,30 +49,30 @@ $(function() {
|
|||
self.titlePrintButton = ko.observable(self.TITLE_PRINT_BUTTON_UNPAUSED);
|
||||
self.titlePauseButton = ko.observable(self.TITLE_PAUSE_BUTTON_UNPAUSED);
|
||||
|
||||
self.estimatedPrintTimeString = ko.computed(function() {
|
||||
self.estimatedPrintTimeString = ko.pureComputed(function() {
|
||||
if (self.lastPrintTime())
|
||||
return formatDuration(self.lastPrintTime());
|
||||
if (self.estimatedPrintTime())
|
||||
return formatDuration(self.estimatedPrintTime());
|
||||
return "-";
|
||||
});
|
||||
self.byteString = ko.computed(function() {
|
||||
self.byteString = ko.pureComputed(function() {
|
||||
if (!self.filesize())
|
||||
return "-";
|
||||
var filepos = self.filepos() ? formatSize(self.filepos()) : "-";
|
||||
return filepos + " / " + formatSize(self.filesize());
|
||||
});
|
||||
self.heightString = ko.computed(function() {
|
||||
self.heightString = ko.pureComputed(function() {
|
||||
if (!self.currentHeight())
|
||||
return "-";
|
||||
return _.sprintf("%.02fmm", self.currentHeight());
|
||||
});
|
||||
self.printTimeString = ko.computed(function() {
|
||||
self.printTimeString = ko.pureComputed(function() {
|
||||
if (!self.printTime())
|
||||
return "-";
|
||||
return formatDuration(self.printTime());
|
||||
});
|
||||
self.printTimeLeftString = ko.computed(function() {
|
||||
self.printTimeLeftString = ko.pureComputed(function() {
|
||||
if (self.printTimeLeft() == undefined) {
|
||||
if (!self.printTime() || !(self.isPrinting() || self.isPaused())) {
|
||||
return "-";
|
||||
|
|
@ -83,19 +83,19 @@ $(function() {
|
|||
return formatFuzzyEstimation(self.printTimeLeft());
|
||||
}
|
||||
});
|
||||
self.progressString = ko.computed(function() {
|
||||
self.progressString = ko.pureComputed(function() {
|
||||
if (!self.progress())
|
||||
return 0;
|
||||
return self.progress();
|
||||
});
|
||||
self.pauseString = ko.computed(function() {
|
||||
self.pauseString = ko.pureComputed(function() {
|
||||
if (self.isPaused())
|
||||
return gettext("Continue");
|
||||
else
|
||||
return gettext("Pause");
|
||||
});
|
||||
|
||||
self.timelapseString = ko.computed(function() {
|
||||
self.timelapseString = ko.pureComputed(function() {
|
||||
var timelapse = self.timelapse();
|
||||
|
||||
if (!timelapse || !timelapse.hasOwnProperty("type"))
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ $(function() {
|
|||
|
||||
self.receiving = ko.observable(false);
|
||||
self.sending = ko.observable(false);
|
||||
self.exchanging = ko.computed(function() {
|
||||
self.exchanging = ko.pureComputed(function() {
|
||||
return self.receiving() || self.sending();
|
||||
});
|
||||
self.callbacks = [];
|
||||
|
|
@ -28,11 +28,11 @@ $(function() {
|
|||
self.translationUploadButton = $("#settings_appearance_managelanguagesdialog_upload_start");
|
||||
|
||||
self.translationUploadFilename = ko.observable();
|
||||
self.invalidTranslationArchive = ko.computed(function() {
|
||||
self.invalidTranslationArchive = ko.pureComputed(function() {
|
||||
var name = self.translationUploadFilename();
|
||||
return name !== undefined && !(_.endsWith(name.toLocaleLowerCase(), ".zip") || _.endsWith(name.toLocaleLowerCase(), ".tar.gz") || _.endsWith(name.toLocaleLowerCase(), ".tgz") || _.endsWith(name.toLocaleLowerCase(), ".tar"));
|
||||
});
|
||||
self.enableTranslationUpload = ko.computed(function() {
|
||||
self.enableTranslationUpload = ko.pureComputed(function() {
|
||||
var name = self.translationUploadFilename();
|
||||
return name !== undefined && name.trim() != "" && !self.invalidTranslationArchive();
|
||||
});
|
||||
|
|
@ -379,7 +379,7 @@ $(function() {
|
|||
return item.display + ((item.english != undefined) ? ' (' + item.english + ')' : '');
|
||||
};
|
||||
|
||||
self.languagePacksAvailable = ko.computed(function() {
|
||||
self.languagePacksAvailable = ko.pureComputed(function() {
|
||||
return self.translations.allSize() > 0;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ $(function() {
|
|||
self.profiles = ko.observableArray();
|
||||
self.printerProfile = ko.observable();
|
||||
|
||||
self.configured_slicers = ko.computed(function() {
|
||||
self.configured_slicers = ko.pureComputed(function() {
|
||||
return _.filter(self.slicers(), function(slicer) {
|
||||
return slicer.configured;
|
||||
});
|
||||
|
|
@ -53,11 +53,11 @@ $(function() {
|
|||
self.profilesForSlicer(newValue);
|
||||
});
|
||||
|
||||
self.enableSlicingDialog = ko.computed(function() {
|
||||
self.enableSlicingDialog = ko.pureComputed(function() {
|
||||
return self.configured_slicers().length > 0;
|
||||
});
|
||||
|
||||
self.enableSliceButton = ko.computed(function() {
|
||||
self.enableSliceButton = ko.pureComputed(function() {
|
||||
return self.gcodeFilename() != undefined
|
||||
&& self.gcodeFilename().trim() != ""
|
||||
&& self.slicer() != undefined
|
||||
|
|
@ -196,4 +196,4 @@ $(function() {
|
|||
["loginStateViewModel", "printerProfilesViewModel"],
|
||||
"#slicing_configuration_dialog"
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -44,14 +44,14 @@ $(function() {
|
|||
self.forceFancyFunctionality = ko.observable(false);
|
||||
self.forceTerminalLogDuringPrinting = ko.observable(false);
|
||||
|
||||
self.fancyFunctionality = ko.computed(function() {
|
||||
self.fancyFunctionality = ko.pureComputed(function() {
|
||||
return self.enableFancyFunctionality() || self.forceFancyFunctionality();
|
||||
});
|
||||
self.terminalLogDuringPrinting = ko.computed(function() {
|
||||
self.terminalLogDuringPrinting = ko.pureComputed(function() {
|
||||
return !self.disableTerminalLogDuringPrinting() || self.forceTerminalLogDuringPrinting();
|
||||
});
|
||||
|
||||
self.displayedLines = ko.computed(function() {
|
||||
self.displayedLines = ko.pureComputed(function() {
|
||||
if (!self.enableFancyFunctionality()) {
|
||||
return self.log();
|
||||
}
|
||||
|
|
@ -77,14 +77,14 @@ $(function() {
|
|||
return result;
|
||||
});
|
||||
|
||||
self.plainLogOutput = ko.computed(function() {
|
||||
self.plainLogOutput = ko.pureComputed(function() {
|
||||
if (self.fancyFunctionality()) {
|
||||
return;
|
||||
}
|
||||
return self.plainLogLines().join("\n");
|
||||
});
|
||||
|
||||
self.lineCount = ko.computed(function() {
|
||||
self.lineCount = ko.pureComputed(function() {
|
||||
if (!self.fancyFunctionality()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ $(function() {
|
|||
self.isReady = ko.observable(undefined);
|
||||
self.isLoading = ko.observable(undefined);
|
||||
|
||||
self.timelapseTypeSelected = ko.computed(function() {
|
||||
self.timelapseTypeSelected = ko.pureComputed(function() {
|
||||
return ("off" != self.timelapseType());
|
||||
});
|
||||
self.intervalInputEnabled = ko.computed(function() {
|
||||
self.intervalInputEnabled = ko.pureComputed(function() {
|
||||
return ("timed" == self.timelapseType());
|
||||
});
|
||||
self.saveButtonEnabled = ko.computed(function() {
|
||||
self.saveButtonEnabled = ko.pureComputed(function() {
|
||||
return self.isDirty() && self.isOperational() && !self.isPrinting() && self.loginState.isUser();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ $(function() {
|
|||
self.editorRepeatedPassword(undefined);
|
||||
});
|
||||
|
||||
self.editorPasswordMismatch = ko.computed(function() {
|
||||
self.editorPasswordMismatch = ko.pureComputed(function() {
|
||||
return self.editorPassword() != self.editorRepeatedPassword();
|
||||
});
|
||||
|
||||
|
|
@ -275,4 +275,4 @@ $(function() {
|
|||
["loginStateViewModel"],
|
||||
[]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ $(function() {
|
|||
}
|
||||
});
|
||||
|
||||
self.passwordMismatch = ko.computed(function() {
|
||||
self.passwordMismatch = ko.pureComputed(function() {
|
||||
return self.access_password() != self.access_repeatedPassword();
|
||||
});
|
||||
|
||||
|
|
@ -112,4 +112,4 @@ $(function() {
|
|||
["loginStateViewModel", "usersViewModel"],
|
||||
["#usersettings_dialog"]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue