When the loader takes a long time before having a website ready to be shown (due to many features selected), it is confusing for users who think the page stopped working. They tend to refresh the page, provoking bugs. To improve the UX, this commit adds: - a browser warning to prevent the user from closing the tab/refreshing - several waiting sentences, depending on the features chosen by the user (the screen switches between them every 10 seconds) - a loading bar whose progression shows the number of installed modules - a solid background instead of a transparent one as there is no value in seeing the preceding background at that point This commit also removes the secondary loader, once the website has been created, to avoid the bad UX of having one long loading, then a refresh, then another loading with the same look. task-3100223 closes odoo/odoo#118525 Signed-off-by: Soukéina Bojabza (sobo) <sobo@odoo.com>
77 lines
3.4 KiB
Python
77 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import werkzeug
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class WebsiteBackend(http.Controller):
|
|
|
|
@http.route('/website/fetch_dashboard_data', type="json", auth='user')
|
|
def fetch_dashboard_data(self, website_id):
|
|
Website = request.env['website']
|
|
has_group_system = request.env.user.has_group('base.group_system')
|
|
has_group_designer = request.env.user.has_group('website.group_website_designer')
|
|
dashboard_data = {
|
|
'groups': {
|
|
'system': has_group_system,
|
|
'website_designer': has_group_designer
|
|
},
|
|
'dashboards': {}
|
|
}
|
|
|
|
current_website = website_id and Website.browse(website_id) or Website.get_current_website()
|
|
multi_website = request.env.user.has_group('website.group_multi_website')
|
|
websites = multi_website and request.env['website'].search([]) or current_website
|
|
dashboard_data['websites'] = websites.read(['id', 'name'])
|
|
for website in dashboard_data['websites']:
|
|
if website['id'] == current_website.id:
|
|
website['selected'] = True
|
|
|
|
if has_group_designer:
|
|
dashboard_data['dashboards']['plausible_share_url'] = current_website._get_plausible_share_url()
|
|
return dashboard_data
|
|
|
|
@http.route('/website/iframefallback', type="http", auth='user', website=True)
|
|
def get_iframe_fallback(self):
|
|
return request.render('website.iframefallback')
|
|
|
|
@http.route('/website/check_new_content_access_rights', type="json", auth='user')
|
|
def check_create_access_rights(self, models):
|
|
"""
|
|
TODO: In master, remove this route and method and find a better way
|
|
to do this. This route is only here to ensure that the "New Content"
|
|
modal displays the correct elements for each user, and there might be
|
|
a way to do it with the framework rather than having a dedicated
|
|
controller route. (maybe by using a template or a JS util)
|
|
"""
|
|
if not request.env.user.has_group('website.group_website_restricted_editor'):
|
|
raise werkzeug.exceptions.Forbidden()
|
|
|
|
return {
|
|
model: request.env[model].check_access_rights('create', raise_exception=False)
|
|
for model in models
|
|
}
|
|
|
|
@http.route('/website/track_installing_modules', type='json', auth='user')
|
|
def website_track_installing_modules(self, selected_features, total_features=None):
|
|
"""
|
|
During the website configuration, this route allows to track the
|
|
website features being installed and their dependencies in order to
|
|
show the progress between installed and yet to install features.
|
|
"""
|
|
features_not_installed = request.env['website.configurator.feature']\
|
|
.browse(selected_features).module_id.upstream_dependencies(exclude_states=('',))\
|
|
.filtered(lambda feature: feature.state != 'installed')
|
|
|
|
# On the 1st run, the total tallies the targeted, not yet installed
|
|
# features. From then on, the compared to total should not change.
|
|
total_features = total_features or len(features_not_installed)
|
|
features_info = {
|
|
'total': total_features,
|
|
'nbInstalled': total_features - len(features_not_installed)
|
|
}
|
|
return features_info
|