move code to vnApp and interceptor
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
0d4ab527c3
commit
fd8375a45a
|
@ -10,6 +10,7 @@ export default class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.loaderStatus = 0;
|
this.loaderStatus = 0;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage(message) {
|
showMessage(message) {
|
||||||
|
@ -38,6 +39,10 @@ export default class App {
|
||||||
if (this.loaderStatus === 0)
|
if (this.loaderStatus === 0)
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getVersion() {
|
||||||
|
this.logger.$http.get('Applications/status');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.service('vnApp', App);
|
ngModule.service('vnApp', App);
|
||||||
|
|
|
@ -30,7 +30,15 @@ function interceptor($q, vnApp, vnToken, $translate) {
|
||||||
},
|
},
|
||||||
response(response) {
|
response(response) {
|
||||||
vnApp.popLoader();
|
vnApp.popLoader();
|
||||||
localStorage.setItem('salix-version', response.headers('salix-version'));
|
const currentVersion = localStorage.getItem('salix-version');
|
||||||
|
const newVersion = response.headers('salix-version');
|
||||||
|
if (newVersion) {
|
||||||
|
if (newVersion != currentVersion) {
|
||||||
|
vnApp.hasNewVersion = true;
|
||||||
|
clearInterval(vnApp.versionInterval);
|
||||||
|
}
|
||||||
|
localStorage.setItem('salix-version', newVersion);
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
responseError(rejection) {
|
responseError(rejection) {
|
||||||
|
@ -38,7 +46,7 @@ function interceptor($q, vnApp, vnToken, $translate) {
|
||||||
const err = new HttpError(rejection.statusText);
|
const err = new HttpError(rejection.statusText);
|
||||||
Object.assign(err, rejection);
|
Object.assign(err, rejection);
|
||||||
return $q.reject(err);
|
return $q.reject(err);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ngModule.factory('vnInterceptor', interceptor);
|
ngModule.factory('vnInterceptor', interceptor);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
id="refresh"
|
id="refresh"
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
ng-if="$ctrl.hasNewVersion"
|
ng-if="$ctrl.vnApp.hasNewVersion"
|
||||||
ng-click="$ctrl.refresh()"
|
ng-click="$ctrl.refresh()"
|
||||||
class="refresh"
|
class="refresh"
|
||||||
translate-attr="{title: 'There is a new version, click here to reload'}">
|
translate-attr="{title: 'There is a new version, click here to reload'}">
|
||||||
|
|
|
@ -3,11 +3,9 @@ import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
export class Layout extends Component {
|
export class Layout extends Component {
|
||||||
constructor($element, $, vnModules, $http) {
|
constructor($element, $, vnModules) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.modules = vnModules.get();
|
this.modules = vnModules.get();
|
||||||
this.$http = $http;
|
|
||||||
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
@ -32,19 +30,8 @@ export class Layout extends Component {
|
||||||
refresh() {
|
refresh() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
getVersion() {
|
|
||||||
const currentVersion = localStorage.getItem('salix-version');
|
|
||||||
this.$http.get('Applications/status').then(res => {
|
|
||||||
const newVersion = res.headers('salix-version');
|
|
||||||
if (newVersion != currentVersion) {
|
|
||||||
this.hasNewVersion = true;
|
|
||||||
clearInterval(this.versionInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Layout.$inject = ['$element', '$scope', 'vnModules', '$http'];
|
Layout.$inject = ['$element', '$scope', 'vnModules'];
|
||||||
|
|
||||||
ngModule.vnComponent('vnLayout', {
|
ngModule.vnComponent('vnLayout', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -37,17 +37,4 @@ describe('Component vnLayout', () => {
|
||||||
expect(url).not.toBeDefined();
|
expect(url).not.toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getVersion()', () => {
|
|
||||||
it('should detect if there is a new version', () => {
|
|
||||||
const frontVersion = '1';
|
|
||||||
localStorage.setItem('salix-version', frontVersion);
|
|
||||||
|
|
||||||
$httpBackend.when('GET', `Applications/status`).respond(200);
|
|
||||||
controller.getVersion();
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
expect(controller.hasNewVersion).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
const packageJson = require('../../../package.json');
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
return function(req, res, next) {
|
return function(req, res, next) {
|
||||||
const packageJson = require('../../../package.json');
|
|
||||||
|
|
||||||
res.set('Salix-Version', packageJson.version);
|
res.set('Salix-Version', packageJson.version);
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue