diff --git a/app/Views/v2/dialog_sample.php b/app/Views/v2/dialog_sample.php index cc26aff..ac2f47a 100644 --- a/app/Views/v2/dialog_sample.php +++ b/app/Views/v2/dialog_sample.php @@ -1,8 +1,8 @@ - + include('v2/dialog_sample'); ?> + include('v2/dialog_val'); ?> + @@ -149,11 +158,11 @@ init() { this.today = new Date().toISOString().slice(0, 10); - this.filter.date1 = "2025-05-05"; - this.filter.date2 = "2025-05-05"; - //this.fetchList(); + this.filter.date1 = "2025-03-03"; + this.filter.date2 = "2025-03-03"; //this.filter.date1 = this.today; //this.filter.date2 = this.today; + this.fetchList(); }, fetchList(){ @@ -193,9 +202,13 @@ get filtered() { let data = this.list; - const valid = this.statusMap[this.filterKey] - if (valid.length > 0) { - data = data.filter(i => valid.includes(i.STATS)); + if (this.filterKey === 'Validated') { + data = data.filter(i => i.ISVAL == 1); + } else { + const valid = this.statusMap[this.filterKey] + if (valid.length > 0) { + data = data.filter(i => valid.includes(i.STATS)); + } } if (this.filterTable) { const s = this.filterTable.toLowerCase(); @@ -205,9 +218,11 @@ ) ); } - return data; }, + get validatedCount() { + return this.list.filter(r => r.ISVAL == 1).length; + }, /* sample dialog @@ -228,10 +243,62 @@ this.item = []; fetch(`${BASEURL}/api/sample/${accessnumber}`, { method: 'GET', headers: {'Content-Type': 'application/json'}}) .then(res => res.json()).then(data => { - this.item = data.data ?? []; + this.item = data.data ?? {}; + if (!Array.isArray(this.item.samples)) this.item.samples = []; }); }, + /* + validate dialog + */ + isDialogValOpen : false, + isValidateEnabled: false, + valAccessnumber : null, + openValDialog (accessnumber) { + this.isDialogValOpen = true; + this.valAccessnumber = accessnumber; + this.$nextTick(() => { + // refs will be available after render + const iframe = this.$root.querySelector('#result-iframe') || (this.$refs && this.$refs.resultIframe); + const validateBtn = this.$root.querySelector('#validate-btn') || (this.$refs && this.$refs.validateBtn); + if (!iframe || !validateBtn) return; + + const setup = () => { + try { + const doc = iframe.contentDocument || iframe.contentWindow.document; + const scrollable = doc.documentElement || doc.body; + const checkScroll = () => { + try { + const atBottom = (scrollable.scrollHeight - scrollable.scrollTop - scrollable.clientHeight) < 2; + this.isValidateEnabled = atBottom; + validateBtn.disabled = !atBottom; + } catch (e) { /* cross-origin or not ready */ } + }; + iframe.contentWindow.removeEventListener('scroll', checkScroll); + iframe.contentWindow.addEventListener('scroll', checkScroll); + checkScroll(); + } catch (e) { /* ignore cross-origin */ } + }; + + // If iframe already loaded, setup immediately; otherwise wait for load + if (iframe.contentWindow && (iframe.contentDocument && iframe.contentDocument.readyState === 'complete')) { + setup(); + } else { + iframe.addEventListener('load', setup); + } + }); + }, + closeValDialog () { + this.isDialogValOpen = false; + }, + unval(accessnumber) { + console.log("Unvalidate access number:", accessnumber); + }, + validate() { + // implement validation action + console.log('Validate clicked for', this.valAccessnumber); + }, + })); });