Skip to content

Commit 06c9bc6

Browse files
added AI changes
1 parent e0777fb commit 06c9bc6

File tree

12 files changed

+346
-118
lines changed

12 files changed

+346
-118
lines changed

ckanext/scheming/assets/js/scheming-suggestions.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ if (typeof window._schemingSuggestionsGlobalState === 'undefined') {
33
datasetId: null,
44
globalInitDone: false,
55
pollAttempts: 0,
6-
isPolling: false // Flag to prevent multiple concurrent poll loops
6+
isPolling: false,
7+
isInitialLoadWithExistingSuggestions: false
78
};
89
}
910

@@ -69,7 +70,6 @@ ckan.module('scheming-suggestions', function($) {
6970

7071
if (!globalState.globalInitDone) {
7172
globalState.globalInitDone = true;
72-
this._showProcessingBanner();
7373
if (!globalState.isPolling) this._pollForSuggestions(); // Start polling if not already
7474
}
7575
this._attachBaseEventHandlers(el, this._popoverDivs[fieldName], fieldName);
@@ -344,7 +344,31 @@ ckan.module('scheming-suggestions', function($) {
344344
} else if (!globalState.isPolling) { // Should not happen if logic is correct, but as a safeguard
345345
globalState.isPolling = true;
346346
}
347-
347+
if (globalState.pollAttempts === 0 && $('#scheming-processing-banner').length === 0) {
348+
var self = this;
349+
// Quick check to see if we should show the banner
350+
$.ajax({
351+
url: (ckan.SITE_ROOT || '') + '/api/3/action/package_show',
352+
data: { id: globalState.datasetId, include_tracking: false },
353+
dataType: 'json',
354+
cache: false,
355+
async: false, // Make synchronous just for this initial check
356+
success: function(response) {
357+
if (response.success && response.result && response.result.dpp_suggestions) {
358+
var status = response.result.dpp_suggestions.STATUS;
359+
if (!status || !self.options.terminalStatuses.includes(status.toUpperCase())) {
360+
self._showProcessingBanner();
361+
}
362+
} else {
363+
self._showProcessingBanner();
364+
}
365+
},
366+
error: function() {
367+
self._showProcessingBanner();
368+
}
369+
});
370+
}
371+
348372
$.ajax({
349373
url: (ckan.SITE_ROOT || '') + '/api/3/action/package_show',
350374
data: { id: globalState.datasetId, include_tracking: false },
@@ -367,6 +391,7 @@ ckan.module('scheming-suggestions', function($) {
367391
if (currentDppStatus === 'DONE') {
368392
console.log("SchemingSuggestions: STATUS is DONE. Applying final updates to formula fields from main dataset object.");
369393
self._updateLiveDatasetAndFormulaFields(datasetObject, dppSuggestionsData);
394+
globalState.isInitialLoadWithExistingSuggestions = (globalState.pollAttempts === 1);
370395
} else if (dppSuggestionsData) { // If dpp_suggestions exists, update its textarea
371396
self._updateLiveDatasetAndFormulaFields(null, dppSuggestionsData); // Only update dpp_suggestions field
372397
}
@@ -375,10 +400,14 @@ ckan.module('scheming-suggestions', function($) {
375400
if (currentDppStatus) {
376401
if (self.options.terminalStatuses.includes(currentDppStatus)) {
377402
if (currentDppStatus === 'DONE') {
378-
self._updateProcessingBanner(self.options.statusDoneText, 'scheming-alert-success');
379-
setTimeout(function() { self._removeProcessingBanner(); }, 5000);
403+
if (!globalState.isInitialLoadWithExistingSuggestions) {
404+
self._updateProcessingBanner(self.options.statusDoneText, 'scheming-alert-success');
405+
setTimeout(function() { self._removeProcessingBanner(); }, 5000);
406+
}
380407
} else { // ERROR, FAILED
381-
self._updateProcessingBanner(self.options.statusErrorText + esc(dppSuggestionsData.STATUS) + '</span>', 'scheming-alert-danger');
408+
if ($('#scheming-processing-banner').length > 0) {
409+
self._updateProcessingBanner(self.options.statusErrorText + esc(dppSuggestionsData.STATUS) + '</span>', 'scheming-alert-danger');
410+
}
382411
}
383412
globalState.isPolling = false; return;
384413
} else { // Ongoing status

0 commit comments

Comments
 (0)