Skip to content

Commit

Permalink
New version 1.1.0
Browse files Browse the repository at this point in the history
- E #51 column visibilty
- E #47 Settings menu name changed
- E #45 sort by material
- B #40 advance color picker relected the current color instead of default red
- B #48 curreny symbol from settings is now directly reflected to edit dialog
- B #33 confirm dialog if small printbutton in filelist view is used
- B #26 auto reload of the usage values
  • Loading branch information
OllisGit committed Sep 1, 2020
1 parent 168ead1 commit 85002f2
Show file tree
Hide file tree
Showing 12 changed files with 492 additions and 62 deletions.
1 change: 0 additions & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exemptLabels:
- "status: inNextRelease"
- "status: inProgress"
- "status: wontfix"
- "type: enhancement"
# Label to use when marking an issue as stale
staleLabel: "status: markedForAutoClose"
# Comment to post when marking an issue as stale. Set to `false` to disable
Expand Down
41 changes: 41 additions & 0 deletions octoprint_SpoolManager/DatabaseManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,24 @@
# List all Models
MODELS = [PluginMetaDataModel, SpoolModel]



class DatabaseManager(object):

class DatabaseSettings:
useExternal = False
# Internal stuff
fileLocation = ""
backupFileLocation = ""
# External stuff
dialect = "postgresql" # sqlite, mysql, postgresql
host = ""
port = 0
user = 0
password = 0



def __init__(self, parentLogger, sqlLoggingEnabled):
self.sqlLoggingEnabled = sqlLoggingEnabled
self._logger = logging.getLogger(parentLogger.name + "." + self.__class__.__name__)
Expand Down Expand Up @@ -168,6 +184,25 @@ def _createDatabaseTables(self):

################################################################################################### public functions


def buildDatabaseSettings(self, pluginSettings):

databaseSettings = self.DatabaseSettings()

# "databaseSettings"] = {
# "useExternal": "true",
# "type": "postgres",
# "host": "localhost",
# "port": 5432,
# "databaseName": "PrintJobDatabase",
# "user": "Olli",
# "password": "illO"



return databaseSettings
pass

def getDatabaseFileLocation(self):
return self._databaseFileLocation

Expand Down Expand Up @@ -301,6 +336,12 @@ def loadAllSpoolsByQuery(self, tableQuery):
myQuery = myQuery.order_by(SpoolModel.remainingWeight.desc())
else:
myQuery = myQuery.order_by(SpoolModel.remainingWeight)
if ("material" == sortColumn):
if ("desc" == sortOrder):
myQuery = myQuery.order_by(SpoolModel.material.desc())
else:
myQuery = myQuery.order_by(SpoolModel.material)

return myQuery


Expand Down
17 changes: 14 additions & 3 deletions octoprint_SpoolManager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _on_printJobFinished(self, printStatus, payload):

self._databaseManager.saveModel(spoolModel)
self._sendDataToClient(dict(
action="reloadTable"
action="reloadTable and sidebarSpools"
))
pass

Expand Down Expand Up @@ -448,13 +448,24 @@ def get_settings_defaults(self):
## Debugging
settings[SettingsKeys.SETTINGS_KEY_SQL_LOGGING_ENABLED] = False

## Database
settings["databaseSettings"] = {
"useExternal": "true",
"type": "postgres",
"host": "localhost",
"port": 5432,
"databaseName": "PrintJobDatabase",
"user": "Olli",
"password": "illO"
}

return settings

##~~ TemplatePlugin mixin
def get_template_configs(self):
return [
dict(type="tab", name="Spools"),
dict(type="settings", custom_bindings=True)
dict(type="settings", custom_bindings=True, name="Spool Manager")
]

##~~ AssetPlugin mixin
Expand Down Expand Up @@ -498,7 +509,7 @@ def get_update_information(self):

# version check: github repository
type="github_release",
user="you",
user="OllisGit",
repo="OctoPrint-SpoolManager",
current=self._plugin_version,

Expand Down
2 changes: 1 addition & 1 deletion octoprint_SpoolManager/models/SpoolModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SpoolModel(BaseModel):
purchasedFrom = CharField(null=True)
purchasedOn = DateField(null=True)
cost = FloatField(null=True)
costUnit = CharField(null=True)
costUnit = CharField(null=True) # deprecated needs to be removed, value should be used from pluginSettings

labels = TextField(null=True)

Expand Down
7 changes: 5 additions & 2 deletions octoprint_SpoolManager/static/js/ComponentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function ComponentFactory(pluginId) {
}

var componentViewModel = {
currentDateTime: ko.observable()
currentDateTime: ko.observable(),
isEnabled: ko.observable(true)
}

var elementSelector = "#" + elementId ;
Expand All @@ -59,7 +60,9 @@ function ComponentFactory(pluginId) {
});

$($(elementSelector).parent().find('span[class=add-on]')[0]).on('click', function () {
$(elementSelector).datetimepicker('show');
if (componentViewModel.isEnabled() == true){
$(elementSelector).datetimepicker('show');
}
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ function SpoolManagerEditSpoolDialog(){


if (editable == true){

var colorViewModel = self.componentFactory.createColorPicker("filament-color-picker");
this.color = colorViewModel.selectedColor;
this.color(DEFAULT_COLOR); // needed
Expand All @@ -168,7 +167,6 @@ function SpoolManagerEditSpoolDialog(){
this.firstUse = firstUseViewModel.currentDateTime;
this.lastUse = lastUseViewModel.currentDateTime;
this.purchasedOn = purchasedOnViewModel.currentDateTime;

}

self.labelsViewModel = self.componentFactory.createLabels("spool-labels-select", $('#spool-form'));
Expand Down Expand Up @@ -534,6 +532,9 @@ function SpoolManagerEditSpoolDialog(){
alert("Displayname not entered!");
return;
}
// workaround
self.spoolItemForEditing.costUnit(self.pluginSettings.currencySymbol())

var noteText = self.noteEditor.getText();
var noteDeltaFormat = self.noteEditor.getContents();
var noteHtml = self.noteEditor.getHtml();
Expand Down
126 changes: 117 additions & 9 deletions octoprint_SpoolManager/static/js/SpoolManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ $(function() {
self.loginState = parameters[0];
self.settingsViewModel = parameters[1];
self.printerStateViewModel = parameters[2];
self.filesViewModel = parameters[3];

self.pluginSettings = null;

Expand Down Expand Up @@ -92,6 +93,22 @@ $(function() {
};

///////////////////////////////////////////////////// START: SETTINGS

self.showLocalBusyIndicator = ko.observable(false);
self.showExternalBusyIndicator = ko.observable(false);
$("#spoolmanger-settings-tab").find('a[data-toggle="tab"]').on('shown', function (e) {
var activatedTab = e.target.hash; // activated tab
var prevTab = e.relatedTarget.hash; // previous tab
console.info("PrevTab:" + prevTab + " ActiveTab:"+activatedTab);

if ("#tab-spool-Storage" == activatedTab){
// self.showLocalBusyIndicator(true);
// self.showExternalBusyIndicator(true);
}
});



self.isFilamentManagerPluginAvailable = ko.observable(false);

self.databaseFileLocation = ko.observable("hello");
Expand Down Expand Up @@ -268,6 +285,46 @@ $(function() {
self.spoolDialog.showDialog(null, closeDialogHandler);
}


var TableAttributeVisibility = function (){
this.displayName = ko.observable(true);
this.material = ko.observable(true);
this.lastFirstUse = ko.observable(true);
this.weight = ko.observable(true);
this.used = ko.observable(true);
this.note = ko.observable(true);
}
self.tableAttributeVisibility = new TableAttributeVisibility();

self.initTableVisibilities = function(){
// load all settings from browser storage
if (!Modernizr.localstorage) {
// damn!!!
return false;
}

assignVisibility = function(attributeName){
var storageKey = "spoolmanager.table.visible." + attributeName;
if (localStorage[storageKey] == null){
localStorage[storageKey] = true
} else {
self.tableAttributeVisibility[attributeName]( "true" == localStorage[storageKey]);
}
self.tableAttributeVisibility[attributeName].subscribe(function(newValue){
localStorage[storageKey] = newValue;
});
}

assignVisibility("displayName");
assignVisibility("material");
assignVisibility("lastFirstUse");
assignVisibility("weight");
assignVisibility("used");
assignVisibility("note");
}



///////////////////////////////////////////////////////////////////////////////////////////////// TABLE BEHAVIOR
self.spoolItemTableHelper = new TableItemHelper(function(tableQuery, observableTableModel, observableTotalItemCount){
// api-call
Expand Down Expand Up @@ -308,19 +365,18 @@ $(function() {


///////////////////////////////////////////////////////////////////////////////////////// OCTOPRINT PRINT-BUTTON
const startPrint = self.printerStateViewModel.print;
self.printerStateViewModel.print = function confirmSpoolSelectionBeforeStartPrint() {

const origStartPrintFunction = self.printerStateViewModel.print;
const newStartPrintFunction = function confirmSpoolSelectionBeforeStartPrint() {
// api-call
self.apiClient.allowedToPrint(function(responseData){
var result = responseData.result;
if ("startPrint" == result){
startPrint();
origStartPrintFunction();
} else {
if ("noSpoolSelected" == result){
var check = confirm('Do you want to start the print without a selected spool?');
if (check == true) {
startPrint();
origStartPrintFunction();
}
return;
}
Expand All @@ -332,27 +388,72 @@ $(function() {
if ("filamentNotEnough" == result){
var check = confirm('Not enough filament. Do you want to start the print anyway?');
if (check == true) {
startPrint();
origStartPrintFunction();
}
return;
}
if ("reminderSpoolSelection" == result){
var question = "Please verify your selected Spool '"+responseData.spoolName+"'. Do you want to start the print anyway?";
var check = confirm(question);
if (check == true) {
startPrint();
origStartPrintFunction();
}
}
}
});
};

self.filesViewModel.loadFile = function confirmSpoolSelectionOnLoadAndPrint(data, printAfterLoad) {
// orig. SourceCode
if (!self.filesViewModel.loginState.hasPermission(self.filesViewModel.access.permissions.FILES_SELECT)) return;

if (!data) {
return;
}

if (printAfterLoad && self.filesViewModel.listHelper.isSelected(data) && self.filesViewModel.enablePrint(data)) {
// file was already selected, just start the print job
// SPOOLMANAGER-CHANGE changed OctoPrint.job.start();
startPrintFunction();
} else {
// select file, start print job (if requested and within dimensions)
var withinPrintDimensions = self.filesViewModel.evaluatePrintDimensions(data, true);
var print = printAfterLoad && withinPrintDimensions;

if (print && self.filesViewModel.settingsViewModel.feature_printStartConfirmation()) {
showConfirmationDialog({
message: gettext("This will start a new print job. Please check that the print bed is clear."),
question: gettext("Do you want to start the print job now?"),
cancel: gettext("No"),
proceed: gettext("Yes"),
onproceed: function() {
OctoPrint.files.select(data.origin, data.path, false).done(function () {
if (print){
newStartPrintFunction();
}
});
},
nofade: true
});
} else {
OctoPrint.files.select(data.origin, data.path, false).done(function () {
if (print){
newStartPrintFunction();
}
});
}
}
};


self.printerStateViewModel.print = newStartPrintFunction;

//////////////////////////////////////////////////////////////////////////////////////////////// OCTOPRINT HOOKS
self.onBeforeBinding = function() {
// assign current pluginSettings
self.pluginSettings = self.settingsViewModel.settings.plugins[PLUGIN_ID];

// Table visibility
self. initTableVisibilities();
// resetSettings-Stuff
new ResetSettingsUtilV2(self.pluginSettings).assignResetSettingsFeature(PLUGIN_ID, function(data){
// no additional reset function needed in V2
Expand Down Expand Up @@ -417,6 +518,12 @@ $(function() {
return;
}

if ("reloadTable and sidebarSpools" == data.action){
self.spoolItemTableHelper.reloadItems();
self.loadSpoolsForSidebar();
return;
}

if ("csvImportStatus" == data.action){
self.csvImportDialog.updateText(data);
return;
Expand Down Expand Up @@ -454,7 +561,8 @@ $(function() {
dependencies: [
"loginStateViewModel",
"settingsViewModel",
"printerStateViewModel"
"printerStateViewModel",
"filesViewModel"
],
// Elements to bind to, e.g. #settings_plugin_SpoolManager, #tab_plugin_SpoolManager, ...
elements: [
Expand Down
Loading

0 comments on commit 85002f2

Please sign in to comment.