Skip to content

Commit

Permalink
wait 118n resolve promise to set initial translation
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Feb 1, 2024
1 parent bd946d9 commit 4a20d4e
Showing 1 changed file with 86 additions and 85 deletions.
171 changes: 86 additions & 85 deletions g3w-admin/qtimeseries/static/qtimeseries/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,101 +14,102 @@
const service = new PluginService();

super({ name: 'qtimeseries', service });

// i18n
const VM = new Vue();
const i18n = async lang => this.setLocale({ [lang]: (await import(BASE_URL + '/i18n/' + lang + '.js')).default });
VM.$watch(() => ApplicationState.language, i18n);
i18n(ApplicationState.language);

const enabled = this.registerPlugin(this.config.gid);

this.setHookLoading({ loading: true });

const project = ApplicationService.getCurrentProject();

// add project layers from config
project
.getConfigLayers()
.filter(l => 'Object' === toRawType(l.qtimeseries))
.forEach(l => {
let {
units = 'd',
start_date = null,
end_date = null,
} = l.qtimeseries;

start_date = moment(start_date).add(new Date(start_date).getTimezoneOffset(), 'minutes');
end_date = moment(end_date).add(new Date(end_date).getTimezoneOffset(), 'minutes');

const u = this.config.steps.find(step_unit => step_unit.qgis === units).moment.split(':');
const multiplier = u.length > 1 ? 1 * u[0] : 1;
const step_unit = u.length > 1 ? u[1] : u[0];
const layer = project.getLayerById(l.id);

this.config.layers.push({
id: l.id,
name: layer.getName(),
wmsname: layer.getWMSLayerName(),
start_date,
end_date,
options: {
range_max: moment(end_date).diff(moment(start_date), step_unit) - 1,
step: l.qtimeseries.step ?? 1,
stepunit: step_unit,
stepunitmultiplier: multiplier,
field: l.qtimeseries.field,
//need to wait promise resolve from
i18n(ApplicationState.language)
.then(()=> {
const enabled = this.registerPlugin(this.config.gid);

this.setHookLoading({ loading: true });

const project = ApplicationService.getCurrentProject();

// add project layers from config
project
.getConfigLayers()
.filter(l => 'Object' === toRawType(l.qtimeseries))
.forEach(l => {
let {
units = 'd',
start_date = null,
end_date = null,
} = l.qtimeseries;

start_date = moment(start_date).add(new Date(start_date).getTimezoneOffset(), 'minutes');
end_date = moment(end_date).add(new Date(end_date).getTimezoneOffset(), 'minutes');

const u = this.config.steps.find(step_unit => step_unit.qgis === units).moment.split(':');
const multiplier = u.length > 1 ? 1 * u[0] : 1;
const step_unit = u.length > 1 ? u[1] : u[0];
const layer = project.getLayerById(l.id);

this.config.layers.push({
id: l.id,
name: layer.getName(),
wmsname: layer.getWMSLayerName(),
start_date,
end_date,
options: {
range_max: moment(end_date).diff(moment(start_date), step_unit) - 1,
step: l.qtimeseries.step ?? 1,
stepunit: step_unit,
stepunitmultiplier: multiplier,
field: l.qtimeseries.field,
}
});
});

// inizialize service
service.config = this.config;
service.toggle = (state) => { service.open = state ?? !service.open; }
service.close = () => { service.open = false; }

this.on('unload', () => service.close())

const show = this.config.layers.length > 0;

service.emit('ready', show);

if (show) {
service.open = false;
}

// setup plugin interface
GUI.isReady().then(() => {
// skip when ...
if(!enabled || !show) {
return;
}
});
});

// inizialize service
service.config = this.config;
service.toggle = (state) => { service.open = state ?? !service.open; }
service.close = () => { service.open = false; }

this.on('unload', () => service.close())

const show = this.config.layers.length > 0;

service.emit('ready', show);

if (show) {
service.open = false;
}

// setup plugin interface
GUI.isReady().then(() => {
// skip when ...
if(!enabled || !show) {
return;
}

this.createSideBarComponent({},
{
...this.config.sidebar,
id: this.name,
events: {
open: {
when: 'before',
cb: bool => {
this._panel = this._panel || new (Vue.extend({
functional: true,
components: { 'qts': httpVueLoader(BASE_URL + '/plugin.vue')},
render: h => h('qts', { props: { service } }),
}))().$mount(ApplicationService.getService('sidebar').getComponent('qtimeseries').getInternalComponent().$el);
service.toggle(bool);

this.createSideBarComponent({},
{
...this.config.sidebar,
id: this.name,
events: {
open: {
when: 'before',
cb: bool => {
this._panel = this._panel || new (Vue.extend({
functional: true,
components: { 'qts': httpVueLoader(BASE_URL + '/plugin.vue')},
render: h => h('qts', { props: { service } }),
}))().$mount(ApplicationService.getService('sidebar').getComponent('qtimeseries').getInternalComponent().$el);
service.toggle(bool);
}
}
}
}
}
}
);
);

this.setReady(true);
});

this.setReady(true);
});
})

this.setHookLoading({ loading: false });

}

});
Expand Down

0 comments on commit 4a20d4e

Please sign in to comment.