Refactor with less awaits (WIP)
This commit is contained in:
parent
64af485a54
commit
13d6004fe8
@ -67,12 +67,17 @@ export class Finding {
|
|||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
async setImages() {
|
* @param {HTMLElement} imageContainer
|
||||||
|
* @param {Function} gallery
|
||||||
|
*/
|
||||||
|
async setImages(imageContainer, gallery) {
|
||||||
let record = await this.fetchData(`${window.API_URL}/finding/${this._data.id}`)
|
let record = await this.fetchData(`${window.API_URL}/finding/${this._data.id}`)
|
||||||
|
|
||||||
if (record.images.length) {
|
if (record.images.length) {
|
||||||
this.images = record.images;
|
this.images = record.images;
|
||||||
|
imageContainer.innerHTML = this.renderImages();
|
||||||
|
gallery('finding-gallery', this.images);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -132,10 +132,11 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
|
|||||||
let layerVincoli = await this.loadLayer('vincoli.geojson', optionsVincoli);
|
let layerVincoli = await this.loadLayer('vincoli.geojson', optionsVincoli);
|
||||||
let layerPaesistici = await this.loadLayer('paesistici.geojson', optionsPaesistici);
|
let layerPaesistici = await this.loadLayer('paesistici.geojson', optionsPaesistici);
|
||||||
|
|
||||||
let markersGroup = await this.sitesMarkers(sitesGroup);
|
// Refactor with separate function...
|
||||||
let notConservedGroup = await this.notConserved();
|
this.sitesMarkers(sitesGroup).then(group => {group.addTo(map); window.Sites = group});
|
||||||
let findingsGroup = await this.findings();
|
this.notConserved().then(group => {group.addTo(map); window.NotConserved = group});
|
||||||
let prehistoric = await this.prehistoric();
|
this.findings().then(group => {group.addTo(map); window.Findings = group});
|
||||||
|
this.prehistoric().then(group => {group.addTo(map); window.Prehistoric = group});
|
||||||
|
|
||||||
const archeo = {
|
const archeo = {
|
||||||
'Vincoli archeologici' : layerVincoli,
|
'Vincoli archeologici' : layerVincoli,
|
||||||
@ -144,16 +145,7 @@ GIS.initMap = async function (mapId, zoomLevel = this.INIT_ZOOM) {
|
|||||||
// TEMP!! Remove point for Lo Pozzo...
|
// TEMP!! Remove point for Lo Pozzo...
|
||||||
sitesGroup.removeLayer(sitesGroup.customGetLayer('lopozzo'));
|
sitesGroup.removeLayer(sitesGroup.customGetLayer('lopozzo'));
|
||||||
|
|
||||||
markersGroup.addTo(map);
|
|
||||||
sitesGroup.addTo(map);
|
sitesGroup.addTo(map);
|
||||||
notConservedGroup.addTo(map);
|
|
||||||
findingsGroup.addTo(map);
|
|
||||||
prehistoric.addTo(map);
|
|
||||||
|
|
||||||
window.Sites = markersGroup;
|
|
||||||
window.NotConserved = notConservedGroup;
|
|
||||||
window.Findings = findingsGroup;
|
|
||||||
window.Prehistoric = prehistoric;
|
|
||||||
|
|
||||||
L.control.layers(baseMap, archeo).addTo(map);
|
L.control.layers(baseMap, archeo).addTo(map);
|
||||||
|
|
||||||
@ -171,7 +163,7 @@ GIS.sitesMarkers = async function (sitesGroup) {
|
|||||||
|
|
||||||
for (let id in MARKER_NAMES.sites) {
|
for (let id in MARKER_NAMES.sites) {
|
||||||
let layer = sitesGroup.customGetLayer(id);
|
let layer = sitesGroup.customGetLayer(id);
|
||||||
let coords = layer.getBounds().getCenter();
|
let coords = layer?.getBounds().getCenter();
|
||||||
const fromStorage = localStorage.getItem(id);
|
const fromStorage = localStorage.getItem(id);
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
|
@ -96,14 +96,12 @@ UI.toggleMenu = function (triggerId, listId = null) {
|
|||||||
* @param {object} data The data retrieved from the DB to display as modal content
|
* @param {object} data The data retrieved from the DB to display as modal content
|
||||||
* @param {string} selector The modal selector
|
* @param {string} selector The modal selector
|
||||||
*/
|
*/
|
||||||
UI.openSiteModal = async function (data, selector) {
|
UI.openSiteModal = function (data, selector) {
|
||||||
const modal = document.querySelector(selector);
|
const modal = document.querySelector(selector);
|
||||||
let dataTabs = modal.querySelectorAll('.data-tabs');
|
let dataTabs = modal.querySelectorAll('.data-tabs');
|
||||||
|
|
||||||
// Reset data tabs content
|
// Reset data tabs content
|
||||||
for (let tab of dataTabs) {
|
for (let tab of dataTabs) tab.innerHTML = '';
|
||||||
tab.innerHTML = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
let siteSheet = new SiteSheet();
|
let siteSheet = new SiteSheet();
|
||||||
siteSheet.siteData = data;
|
siteSheet.siteData = data;
|
||||||
@ -161,7 +159,7 @@ UI.openSiteModal = async function (data, selector) {
|
|||||||
* @param {object} data The data retrieved from the DB to display as modal content
|
* @param {object} data The data retrieved from the DB to display as modal content
|
||||||
* @param {string} selector The modal selector
|
* @param {string} selector The modal selector
|
||||||
*/
|
*/
|
||||||
UI.openNotConserModal = async function (data, selector) {
|
UI.openNotConserModal = function (data, selector) {
|
||||||
const modal = document.querySelector(selector);
|
const modal = document.querySelector(selector);
|
||||||
|
|
||||||
let sheet = new NotConservedSheet();
|
let sheet = new NotConservedSheet();
|
||||||
@ -169,21 +167,19 @@ UI.openNotConserModal = async function (data, selector) {
|
|||||||
// For Stimulus biblio_controller
|
// For Stimulus biblio_controller
|
||||||
window.Biblio = sheet;
|
window.Biblio = sheet;
|
||||||
|
|
||||||
modal.querySelector('#not-conser-sheet').innerHTML = await sheet.render();
|
sheet.render().then(html => modal.querySelector('#not-conser-sheet').innerHTML = html);
|
||||||
modal.classList.add('is-active');
|
modal.classList.add('is-active');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {object} data The data retrieved from the DB to display as modal content
|
* @param {object} data The data retrieved from the DB to display as modal content
|
||||||
* @param {string} selector The modal selector
|
* @param {string} selector The modal selector
|
||||||
*/
|
*/
|
||||||
UI.openFindingModal = async function (data, selector) {
|
UI.openFindingModal = function (data, selector) {
|
||||||
const modal = document.querySelector(selector);
|
const modal = document.querySelector(selector);
|
||||||
let dataTabs = modal.querySelectorAll('.data-tabs');
|
let dataTabs = modal.querySelectorAll('.data-tabs');
|
||||||
|
|
||||||
// Reset data tabs content
|
// Reset data tabs content
|
||||||
for (let tab of dataTabs) {
|
for (let tab of dataTabs) tab.innerHTML = '';
|
||||||
tab.innerHTML = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
let finding = new Finding();
|
let finding = new Finding();
|
||||||
finding.data = data;
|
finding.data = data;
|
||||||
@ -191,12 +187,9 @@ UI.openFindingModal = async function (data, selector) {
|
|||||||
// For Stimulus biblio_controller
|
// For Stimulus biblio_controller
|
||||||
window.Biblio = finding;
|
window.Biblio = finding;
|
||||||
|
|
||||||
finding.setImages();
|
finding.render().then(html => modal.querySelector('#finding-sheet').innerHTML = html);
|
||||||
modal.querySelector('#finding-sheet').innerHTML = await finding.render();
|
finding.setImages(modal.querySelector('#photos'), this.imageGallery);
|
||||||
if (finding.images) {
|
|
||||||
modal.querySelector('#photos').innerHTML = finding.renderImages();
|
|
||||||
this.imageGallery('finding-gallery', finding.images);
|
|
||||||
}
|
|
||||||
modal.classList.add('is-active');
|
modal.classList.add('is-active');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -204,7 +197,7 @@ UI.openFindingModal = async function (data, selector) {
|
|||||||
* @param {object} data The data retrieved from the DB to display as modal content
|
* @param {object} data The data retrieved from the DB to display as modal content
|
||||||
* @param {string} selector The modal selector
|
* @param {string} selector The modal selector
|
||||||
*/
|
*/
|
||||||
UI.openPrehistModal = async function (data, selector) {
|
UI.openPrehistModal = function (data, selector) {
|
||||||
const modal = document.querySelector(selector);
|
const modal = document.querySelector(selector);
|
||||||
|
|
||||||
let prehistoric = new Prehistoric();
|
let prehistoric = new Prehistoric();
|
||||||
@ -212,8 +205,7 @@ UI.openPrehistModal = async function (data, selector) {
|
|||||||
|
|
||||||
// For Stimulus biblio_controller
|
// For Stimulus biblio_controller
|
||||||
//window.Biblio = prehistoric;
|
//window.Biblio = prehistoric;
|
||||||
|
prehistoric.render().then(html => modal.querySelector('#prehist-sheet').innerHTML = html);
|
||||||
modal.querySelector('#prehist-sheet').innerHTML = await prehistoric.render();
|
|
||||||
modal.classList.add('is-active');
|
modal.classList.add('is-active');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user