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() {
|
||||
this.loaderStatus = 0;
|
||||
this.loading = false;
|
||||
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
|
||||
}
|
||||
|
||||
showMessage(message) {
|
||||
|
@ -38,6 +39,10 @@ export default class App {
|
|||
if (this.loaderStatus === 0)
|
||||
this.loading = false;
|
||||
}
|
||||
|
||||
getVersion() {
|
||||
this.logger.$http.get('Applications/status');
|
||||
}
|
||||
}
|
||||
|
||||
ngModule.service('vnApp', App);
|
||||
|
|
|
@ -30,7 +30,15 @@ function interceptor($q, vnApp, vnToken, $translate) {
|
|||
},
|
||||
response(response) {
|
||||
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;
|
||||
},
|
||||
responseError(rejection) {
|
||||
|
@ -38,7 +46,7 @@ function interceptor($q, vnApp, vnToken, $translate) {
|
|||
const err = new HttpError(rejection.statusText);
|
||||
Object.assign(err, rejection);
|
||||
return $q.reject(err);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
ngModule.factory('vnInterceptor', interceptor);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<vn-icon-button
|
||||
id="refresh"
|
||||
icon="refresh"
|
||||
ng-if="$ctrl.hasNewVersion"
|
||||
ng-if="$ctrl.vnApp.hasNewVersion"
|
||||
ng-click="$ctrl.refresh()"
|
||||
class="refresh"
|
||||
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';
|
||||
|
||||
export class Layout extends Component {
|
||||
constructor($element, $, vnModules, $http) {
|
||||
constructor($element, $, vnModules) {
|
||||
super($element, $);
|
||||
this.modules = vnModules.get();
|
||||
this.$http = $http;
|
||||
this.versionInterval = setInterval(this.getVersion.bind(this), 300000);
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
|
@ -32,19 +30,8 @@ export class Layout extends Component {
|
|||
refresh() {
|
||||
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', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -37,17 +37,4 @@ describe('Component vnLayout', () => {
|
|||
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) {
|
||||
return function(req, res, next) {
|
||||
const packageJson = require('../../../package.json');
|
||||
|
||||
res.set('Salix-Version', packageJson.version);
|
||||
next();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue