partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 71a93a016c2885bb304157712d6e56b0e94b7052
parent 209ec5ea19cb04c141c3bab8132a3739ce216607
Author: Felicitus <felicitus@felicitus.org>
Date:   Mon, 12 Oct 2015 15:42:04 +0200

Removed session manager, migrated system notice icon in the toolbar

Diffstat:
Dsrc/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js | 105-------------------------------------------------------------------------------
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeEditorComponent.js | 10+++++++++-
Msrc/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeGrid.js | 15+++++++--------
Asrc/PartKeepr/FrontendBundle/Resources/public/js/Data/store/SystemNoticeStore.js | 35+++++++++++++++++++++++++++++++++++
Msrc/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js | 69++++++++-------------------------------------------------------------
Msrc/PartKeepr/FrontendBundle/Resources/views/index.html.twig | 2+-
6 files changed, 60 insertions(+), 176 deletions(-)

diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/Session/SessionManager.js @@ -1,105 +0,0 @@ -/** - * Represents a session against the PartKeepr Server. - */ -Ext.define("PartKeepr.SessionManager", { - extend: 'Ext.util.Observable', - - /** - * Holds the current session ID, or null if no session is active - * - * @var string - */ - session: null, - - /** - * Holds an instance of the login dialog, or "null" if no login dialog is active. - * - * @var object - */ - loginDialog: null, - - - /** - * Constructs a new SessionManager. - * - * @param config Optional: Specifies a configuration object - */ - constructor: function (config) - { - this.callParent(arguments); - }, - - /** - * Creates and shows the login dialog, as well as setting up any event handlers. - */ - login: function (username, password) - { - this.loginDialog = Ext.create("PartKeepr.LoginDialog"); - - if (username && password) { - this.onLogin(username, password); - } else { - this.loginDialog.on("login", this.onLogin, this); - this.loginDialog.show(); - } - }, - /** - * Removes the current session. - */ - logout: function () - { - this.session = null; - }, - /** - * Callback from the login dialog when the "login" button was clicked. - * - * @param username The username, as entered in the login dialog - * @param password The password, as entered - */ - onLogin: function (username, password) - { - this.username = username; - this.password = password; - - var k = new PartKeepr.ServiceCall("auth", "getSalt"); - k.setParameter("username", username); - k.setHandler(Ext.bind(this.onSaltRetrieved, this)); - k.doCall(); - - - }, - /** - * Callback when the service call is complete. - * - * @param response The session ID - */ - onAfterLogin: function (response) - { - this.setSession(response.sessionId); - this.loginDialog.destroy(); - - PartKeepr.getApplication().setAdmin(response.isAdmin); - PartKeepr.getApplication().setUsername(response.username); - - PartKeepr.getApplication().setInitialUserPreferences(response.userPreferences); - - this.fireEvent("login"); - - }, - /** - * Sets the session - */ - setSession: function (sessionid) - { - this.session = sessionid; - }, - /** - * Returns the current session - * - * @returns the session, or null if no session is available - */ - getSession: function () - { - return this.session; - } -}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeEditorComponent.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeEditorComponent.js @@ -12,11 +12,19 @@ Ext.define('PartKeepr.SystemNoticeEditorComponent', { initComponent: function () { this.createStore({ + filters: [ + { + property: 'acknowledged', + operator: "=", + value: false + } + ], sorters: [ { property: 'date', direction: 'DESC' - } + }, + ] }); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeGrid.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Components/SystemNotice/SystemNoticeGrid.js @@ -2,10 +2,10 @@ * Represents the project grid */ Ext.define('PartKeepr.SystemNoticeGrid', { - extend: 'PartKeepr.EditorGrid', - alias: 'widget.SystemNoticeGrid', - columns: [ - {header: i18n("Name"), dataIndex: 'title', flex: 1} - ], - enableTopToolbar: false -});- \ No newline at end of file + extend: 'PartKeepr.EditorGrid', + alias: 'widget.SystemNoticeGrid', + columns: [ + {header: i18n("Name"), dataIndex: 'title', flex: 1} + ], + enableTopToolbar: false +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/Data/store/SystemNoticeStore.js b/src/PartKeepr/FrontendBundle/Resources/public/js/Data/store/SystemNoticeStore.js @@ -0,0 +1,35 @@ +Ext.define('PartKeepr.data.store.SystemNoticeStore', { + extend: 'Ext.data.Store', + + /** + * The store ID to use + */ + storeId: 'SystemNoticeStore', + + /** + * Automatically load the store + */ + autoLoad: true, + + /** + * The model to use + */ + model: "PartKeepr.CoreBundle.Entity.SystemNotice", + + pageSize: 99999999, + + sorters: [ + { + property: 'date', + direction: 'DESC' + } + ], + + filters: [ + { + property: 'acknowledged', + operator: "=", + value: false + } + ] +}); diff --git a/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js b/src/PartKeepr/FrontendBundle/Resources/public/js/PartKeepr.js @@ -23,8 +23,6 @@ Ext.application({ var authenticationProvider = Ext.create(window.parameters.authentication_provider); PartKeepr.Auth.AuthenticationProvider.setAuthenticationProvider(authenticationProvider); - this.sessionManager = new PartKeepr.SessionManager(); - var config = {}; if (window.parameters.autoLoginUsername) { @@ -78,8 +76,6 @@ Ext.application({ this.getUserPreferenceStore().loadRecords(records.records); } - this.reloadStores(); - this.createPartManager(); this.menuBar.enable(); @@ -198,15 +194,6 @@ Ext.application({ alert(i18n("The following cronjobs aren't running:") + "\n\n" + data.inactiveCronjobs.join("\n")); } }, - /** - * Returns the session manager - * - * @returns SessionManager - */ - getSessionManager: function () - { - return this.sessionManager; - }, /* * Checks for unacknowledged system notices. Triggers a service call against the server. * @@ -217,26 +204,24 @@ Ext.application({ */ doUnacknowledgedNoticesCheck: function () { - if (this.getSessionManager().getSession() !== null) { - var call = new PartKeepr.ServiceCall("SystemNotice", "hasUnacknowledgedNotices"); - - call.setHandler(Ext.bind(this.onUnacknowledgedNoticesCheck, this)); - call.doCall(); - } + this.systemNoticeStore.load({ + scope: this, + callback: this.onUnacknowledgedNoticesCheck + }); }, /** * Handler for the unacknowledged system notices check * @param data The data returned from the server */ - onUnacknowledgedNoticesCheck: function (data) + onUnacknowledgedNoticesCheck: function () { - if (data.data.unacknowledgedNotices === true) { + if (this.systemNoticeStore.count() > 0) { this.statusBar.systemNoticeButton.show(); } else { this.statusBar.systemNoticeButton.hide(); } - Ext.defer(this.doUnacknowledgedNoticesCheck, 10000, this); + Ext.defer(this.doUnacknowledgedNoticesCheck, 100000, this); }, createGlobalStores: function () { @@ -296,6 +281,7 @@ Ext.application({ this.tipOfTheDayStore = Ext.create("PartKeepr.data.store.TipOfTheDayStore"); this.tipOfTheDayHistoryStore = Ext.create("PartKeepr.data.store.TipOfTheDayHistoryStore"); + this.systemNoticeStore = Ext.create("PartKeepr.data.store.SystemNoticeStore"); }, storeLoaded: function (store) @@ -403,31 +389,6 @@ Ext.application({ return str_replace("µ", "μ", value); }, /** - * Reload all global stores each 100 seconds. - * - * @todo In the future, it would be nice to trigger a specific - * store reload when something happens. Example: - * - * If the user pulls down the storage location combo box, - * reload it. - * - * YES, this is becoming nasty. We have now 6 stores, each - * reloading every minute. This NEEDS to be fixed soon! - * - */ - reloadStores: function () - { - if (this.getSessionManager().getSession()) { - this.footprintStore.load(); - this.manufacturerStore.load(); - this.distributorStore.load(); - this.partUnitStore.load(); - this.unitStore.load(); - this.userStore.load(); - Ext.defer(PartKeepr.getApplication().reloadStores, 100000, this); - } - }, - /** * Creates the main view of PartKeepr. */ createLayout: function () @@ -529,20 +490,6 @@ Ext.application({ { return this.statusBar; }, - getSession: function () - { - return this.getSessionManager().getSession(); - }, - setSession: function (session) - { - if (session) { - this.getStatusbar().getConnectionButton().setConnected(); - } else { - this.getStatusbar().getConnectionButton().setDisconnected(); - this.setUsername(""); - } - - }, /** * Sets the username. This should only be called from the login dialog. * diff --git a/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig b/src/PartKeepr/FrontendBundle/Resources/views/index.html.twig @@ -142,7 +142,6 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/TimeDisplay.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Menu.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Widgets/UrlTextField.js' - '@PartKeeprFrontendBundle/Resources/public/js/Components/Session/SessionManager.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/Preferences/DisplayPreferencesPanel.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/Preferences/UserPasswordChangePanel.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/User/Preferences/StockPreferences.js' @@ -200,6 +199,7 @@ '@PartKeeprFrontendBundle/Resources/public/js/Components/Statistics/StatisticsChartPanel.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/Statistics/CurrentStatisticsPanel.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/CategoryStore.js' + '@PartKeeprFrontendBundle/Resources/public/js/Data/store/SystemNoticeStore.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/TipOfTheDay/TipOfTheDayWindow.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/CategoryTree.js' '@PartKeeprFrontendBundle/Resources/public/js/Components/CategoryEditor/CategoryEditorTree.js'