strolch-maven-archetypes/li.strolch.mvn.archetype.we.../src/main/resources/archetype-resources/src/main/webapp/app/src/main/c-main.html

269 lines
11 KiB
HTML

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
<link rel="import" href="../../bower_components/app-layout/app-drawer/app-drawer.html">
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../../bower_components/strolch-wc-debounced-input/strolch-wc-debounced-input.html">
<link rel="import" href="../../bower_components/strolch-wc-notification/strolch-wc-notification.html">
<link rel="import" href="../../bower_components/strolch-wc-information-dialog/strolch-wc-information-dialog.html">
<link rel="import" href="../behaviors/c-app-behavior.html">
<link rel="import" href="../styles/c-app-style.html">
<link rel="import" href="../utils/c-app-routing.html">
<link rel="import" href="./c-drawer.html">
<link rel="import" href="./c-pages.html">
<dom-module id="c-main">
<template>
<style is="custom-style" include="c-app-style">
:root {
display: block;
}
app-toolbar {
background-color: var(--app-primary-color);
color: var(--app-regular-highlight-fg-color);
}
strolch-wc-debounced-input {
--focus-color: white;
--input-color: white;
--regular-color: white;
}
</style>
<!-- Routing -->
<c-app-routing id="appRouting"
login-page="login"
auth-valid="[[authTokenValid]]"
page="{{page}}"
route-tail="{{routeTail}}"
use-hash-as-path></c-app-routing>
<app-drawer-layout fullbleed force-narrow>
<template is="dom-if" if="[[authTokenValid]]">
<c-drawer id="drawer" page="[[page]]" auth-token-valid="[[authTokenValid]]" user-config="[[userConfig]]" version="[[version]]"
on-strolch-app-version-outdated="onAppVersionOutdated"></c-drawer>
<app-toolbar>
<paper-icon-button icon="menu" on-tap="toggleDrawer"></paper-icon-button>
<div main-title>[[localize(page)]]</div>
<template is="dom-if" if="[[toolbarConfig.hasSearchTerm]]">
<strolch-wc-debounced-input id="debouncedInput"
debounced-input="{{searchTerm}}"></strolch-wc-debounced-input>
</template>
</app-toolbar>
</template>
<template is="dom-repeat" items="[[notifications]]" as="notification">
<strolch-wc-notification message="[[notification.message]]"
action1="[[notification.action1]]"
action2="[[notification.action2]]"
action3="[[notification.action3]]"
callback1="[[notification.callback1]]"
callback2="[[notification.callback2]]"
callback3="[[notification.callback3]]"
bind="[[notification.bind]]"
fa-icon="[[notification.faIcon]]"></strolch-wc-notification>
</template>
<c-pages id="pages" page="[[page]]" toolbar-config="{{toolbarConfig}}" route="{{routeTail}}" search-term="[[searchTerm]]"
user-location="{{userLocation}}"></c-pages>
<paper-toast id="toast" text="[[toastText]]"></paper-toast>
<paper-toast id="newVersionAvailableToast" duration="0">
<paper-button class="refresh" on-tap="refreshBrowser">[[localize('refresh')]]</paper-button>
</paper-toast>
</app-drawer-layout>
<strolch-wc-information-dialog id="infoDlg"
locales-path="../../../locales.json"></strolch-wc-information-dialog>
<!-- Ajax requests -->
<iron-ajax id="ajaxGetAppVersion"
url="[[baseRestPath]]/strolch/version"
content-type="application/json"
handle-as="json"
method="GET"
on-response="onGetAppVersionResponse"
on-error="onGetAppVersionError"></iron-ajax>
</template>
<script>
Polymer({
is: 'c-main',
behaviors: [
CustomAppBehavior
],
properties: {
toolbarConfig: {
type: Object
},
searchTerm: {
type: String
},
page: {
type: String
},
authToken: {
type: String
},
authTokenValid: {
type: Boolean,
value: false
},
userConfig: {
type: Object
},
route: {
type: Object
},
toastText: {
type: String,
value: 'not-yet-set'
},
version: {
type: Object
}
},
observers: [],
listeners: {
"strolch-session-valid": "onSessionValidated",
"strolch-reload": "reload",
"strolch-show-toast": "onShowToast",
"strolch-server-not-available": "onServerNotAvailable",
"strolch-session-invalid": "onSessionInvalid",
"strolch-privilege-denied": "onPrivilegeDenied",
"strolch-change-page": "onPageChange",
"strolch-show-dialog": "onShowDialog",
"strolch-show-info": "onShowInfo",
"strolch-ajax-request-error": "onRequestError",
"strolch-show-notification": "onShowNotification",
"strolch-clear-notification": "onClearNotification",
"strolch-clear-search-term": "onClearSearchTerm",
"cx-logout": "onLogOut",
},
reload: function () {
this.reloadPage(this.page);
},
toggleDrawer: function () {
this.$$("#drawer").toggleDrawer();
},
closeDrawer: function () {
this.$$("#drawer").closeDrawer();
},
onPageChange: function (e) {
this.closeDrawer();
if (e && e.detail && e.detail.page) {
var pageName = e.detail.page;
// set the next page
document.title = this.localize == null ? pageName : this.localize(pageName);
this.$.appRouting.pushNextPage(pageName, e.detail.keepQueryParams);
} else {
console.log("received page change without new value");
}
},
onShowInfo: function (e) {
this.$.infoDlg.open(e.detail);
},
onSessionValidated: function () {
console.log("Session validated.");
this.set("authToken", Strolch.getAuthToken());
this.set("authTokenValid", true);
this.set("userConfig", Strolch.getUserConfig());
this.$.ajaxGetAppVersion.generateRequest();
},
onGetAppVersionResponse: function (event) {
this.version = event.detail.response;
Strolch.setAppVersion(this.version);
var artifactVersion = this.version.appVersion.artifactVersion;
var scmRevision = this.version.appVersion.scmRevision;
console.log("App Version is " + artifactVersion);
var currentVersion = sessionStorage.appScmRevision;
if (currentVersion == null //
|| currentVersion === 'undefined' //
|| scmRevision == null
|| scmRevision === 'undefined') {
sessionStorage.appScmRevision = scmRevision;
console.log("App SCM Revision is now known as " + scmRevision);
} else if (scmRevision !== currentVersion) {
console.log("App SCM Revision has changed from " + currentVersion + " to " + scmRevision + ". Need to refresh browser...");
this.fire("strolch-app-version-outdated", {newVersion: scmRevision});
this.$.newVersionAvailableToast.text = this.localize('newVersionAvailableRefreshRequired') + ": " + artifactVersion;
this.$.newVersionAvailableToast.open();
}
},
onGetAppVersionError: function (event) {
console.log(event);
var readyState = event.detail.request.xhr.readyState;
var status = event.detail.request.xhr.status;
if (readyState === 4 && status === 404) {
console.log("Ignoring 404 for get version, as server is probably still starting...");
} else {
this.onRequestError(event);
}
},
refreshBrowser: function () {
sessionStorage.appScmRevision = this.version.appVersion.scmRevision;
document.location.reload();
},
checkForNewVersion: function () {
this.$.ajaxGetAppVersion.generateRequest();
},
reconnect: function () {
this.onGetAppVersionResponse = function (event) {
var version = event.detail.response;
this.scmRevision = version.appVersion.scmRevision;
sessionStorage.appScmRevision = this.scmRevision;
document.location.reload();
};
this.$.ajaxGetAppVersion.generateRequest();
},
/* Lifecycle */
attached: function () {
setTimeout(function () {
this.checkForNewVersion();
}.bind(this), 5000);
this.checkForNewVersionInterval = setInterval(function () {
this.checkForNewVersion();
}.bind(this), 300000);
window.addEventListener("beforeunload", function (e) {
console.log("App SCM Revision " + sessionStorage.appScmRevision + " is cleared due to unload of UI");
delete sessionStorage.appScmRevision;
return null;
});
},
});
</script>
</dom-module>