Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Johnson committed Dec 10, 2023
2 parents 104003e + 6cf4768 commit 379bd39
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist
.DS_Store
*.zip
.venv
.vscode
76 changes: 57 additions & 19 deletions octoprint_SpoolManager/static/js/SpoolManager-EditSpoolDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,23 @@ function SpoolManagerEditSpoolDialog(){
var convertedDateTime = moment(data.firstUse, "DD.MM.YYYY HH:mm").format("YYYY-MM-DDTHH:mm")
this.firstUseKO(convertedDateTime);
}
else{
this.firstUseKO(null);
}
if (updateData.lastUse){
var convertedDateTime = moment(data.lastUse, "DD.MM.YYYY HH:mm").format("YYYY-MM-DDTHH:mm")
this.lastUseKO(convertedDateTime);
}
else{
this.lastUseKO(null);
}
if (updateData.purchasedOn){
var convertedDateTime = moment(data.purchasedOn, "DD.MM.YYYY").format("YYYY-MM-DD")
this.purchasedOnKO(convertedDateTime);
}
else {
this.purchasedOnKO(null);
}

this.purchasedFrom(updateData.purchasedFrom);

Expand Down Expand Up @@ -827,9 +836,11 @@ function SpoolManagerEditSpoolDialog(){
// self.spoolItemForEditing.lastUse(null);
// self.spoolItemForEditing.lastUseKO(null);
// self.spoolItemForEditing.purchasedOn(null);
// self.spoolItemForEditing.purchasedOnKO(null);
// self.spoolItemForEditing.remainingCombinedWeight(0);
// self.spoolItemForEditing.totalCombinedWeight(0);

// Force the current day on new spools
self.spoolItemForEditing.purchasedOnKO(moment().format("YYYY-MM-DD"))
} else {
self.isExistingSpool(true);
// Make a copy of provided spoolItem
Expand Down Expand Up @@ -859,46 +870,73 @@ function SpoolManagerEditSpoolDialog(){
self._copySpoolItemForEditing(self.spoolItemForEditing);
}

self.copySpoolItemFromTemplate = function(spoolItem){
self.copySpoolItemFromTemplate = function (spoolItem) {
// Copy everything
self._copySpoolItemForEditing(spoolItem);
// reset values that should'nt be copied
// Reset values that shouldn't be copied

var defaultExcludedNumericFields = [
"usedLength",
"usedLengthPercentage",
"usedWeight",
"usedPercentage",
];

var defaultExcludedFields = [
"selectedForTool",
"version",
"firstUseKO",
"lastUseKO",
"remainingWeight",
"remainingPercentage",
"remainingLength",
"remainingLengthPercentage",
"totalCombinedWeight",
"remainingCombinedWeight",
].concat(defaultExcludedNumericFields);


var defaultExcludedFields = ["selectedForTool","version", "databaseId", "isTemplate","firstUseKO", "lastUseKO",
"remainingWeight","remainingPercentage","usedLength", "usedLengthPercentage","remainingLength", "remainingLengthPercentage",
"usedWeight", "usedPercentage", "totalCombinedWeight", "remainingCombinedWeight"];
var allFieldNames = Object.keys(spoolItem);
for (const fieldName of allFieldNames){
if (self.pluginSettings.excludedFromTemplateCopy().includes(fieldName) ||
defaultExcludedFields.includes(fieldName)){
var currentValue = self.spoolItemForEditing[fieldName]();
self.spoolItemForEditing[fieldName]("");
var excludedFieldsFromSettings =
self.pluginSettings.excludedFromTemplateCopy();
for (const fieldName of allFieldNames) {
if (
excludedFieldsFromSettings.includes(fieldName) ||
defaultExcludedFields.includes(fieldName)
) {
if (defaultExcludedNumericFields.includes(fieldName)) {
self.spoolItemForEditing[fieldName]("0");
} else {
self.spoolItemForEditing[fieldName]("");
}
}
}
if (self.pluginSettings.excludedFromTemplateCopy().includes("allNotes")) {
if (excludedFieldsFromSettings.includes("allNotes")) {
if (self.noteEditor != null) {
self.noteEditor.setText("", 'api');
self.noteEditor.setText("", "api");
}
// self.spoolItemForEditing["noteText"]("");
// self.spoolItemForEditing["noteDeltaFormat"]("");
// self.spoolItemForEditing["noteHtml"]("");
}
// Trigger the auto-calculation
var copiedWeight = self.spoolItemForEditing["spoolWeight"]();
self.spoolItemForEditing.spoolWeight(0);
self.spoolItemForEditing.spoolWeight(copiedWeight);

// close dialog
self.templateSpoolDialog.modal('hide');
}
self.templateSpoolDialog.modal("hide");
};

self._copySpoolItemForEditing = function(spoolItem){
self._copySpoolItemForEditing = function (spoolItem) {
self.isExistingSpool(false);
let spoolItemCopy = ko.mapping.toJS(spoolItem);
self.spoolItemForEditing.update(spoolItemCopy);
self.spoolItemForEditing.isTemplate(false);
// self.spoolItemForEditing.isActive(true); is set by 'isInActive'
// This sets isActive as well
self.spoolItemForEditing.isInActive(false);
self.spoolItemForEditing.databaseId(null);
self.spoolItemForEditing.isSpoolVisible(true);
}
};

self.saveSpoolItem = function(){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ FPE; 2.16
<!-- Template - TAB -->
<div class="tab-pane" id="tab-spool-Template">
<div>
Which fields should be copied from the template spool during adding a new new spool?
Which fields should be copied when creating a new spool from a template?
</div>
<br/>
<div class="control-group">
Expand Down

0 comments on commit 379bd39

Please sign in to comment.