cartodb-4.42/lib/assets/javascripts/dashboard/data/background-polling/dashboard-background-polling-model.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
const BackgroundPollingModel = require('dashboard/data/background-polling/background-polling-model');
/**
* Background polling model for the dashboard context.
*/
module.exports = BackgroundPollingModel.extend({
_onImportsStateChange: function (importsModel) {
if (this._shouldRedirect(importsModel)) {
this._redirectTo(importsModel.getRedirectUrl(this._userModel));
return;
}
if (importsModel.hasCompleted()) {
this.trigger('importCompleted', importsModel, this);
}
},
/**
* Determines if the user can be redirected after the given
* import has been completed. The following conditions must be true:
* - Import has been completed
* - No imports are still running
* - No other imports have been previously completed
* - Import has a redirect URL for the given user
* - Import was NOT a twitter import
* - Number of tables created:
* - n if import was a .carto file
* - 1 otherwise
*/
_shouldRedirect: function (importsModel) {
return importsModel.hasCompleted() &&
this.importsCollection.allImportsCompletedOrFailed() &&
this.importsCollection.getCompletedItemsCount() === 1 &&
!importsModel.isTwitterImport() &&
importsModel.getRedirectUrl(this._userModel) &&
(importsModel.getNumberOfTablesCreated() === 1 ||
importsModel.isCartoImport());
},
_redirectTo: function (url) {
window.location = url;
}
});