Bump bootbox to 5.5.2, preload view javascript

This commit is contained in:
Katharina Bogad 2021-06-24 15:55:42 +02:00
parent 77e365985f
commit f051f05341
25 changed files with 200 additions and 28 deletions

View File

@ -72,6 +72,7 @@ class FilesApiController extends BaseApiController
if (file_exists($filePath))
{
// TODO: ACCEPT JSON
$response->write(file_get_contents($filePath));
$response = $response->withHeader('Cache-Control', 'max-age=2592000');
$response = $response->withHeader('Content-Type', mime_content_type($filePath));

View File

@ -11,6 +11,8 @@ class batterycard
this.scope = scopeSelector != null ? $(scopeSelector) : $(document);
var jScope = this.scope;
this.$ = scopeSelector != null ? (selector) => jScope.find(selector) : $;
this.Grocy.PreloadView("batteriesjournal");
}
Refresh(batteryId)

View File

@ -11,6 +11,8 @@ class chorecard
this.scope = scopeSelector != null ? $(scopeSelector) : $(document);
var jScope = this.scope;
this.$ = scopeSelector != null ? (selector) => jScope.find(selector) : $;
this.Grocy.PreloadView("choresjournal");
}
Refresh(choreId)

View File

@ -28,6 +28,10 @@ class productcard
.find("a[data-toggle='collapse']")
.text(self.Grocy.translate("Show more"));
})
// preload some views.
this.Grocy.PreloadView("stockentries");
this.Grocy.PreloadView("stockjournal");
}
Refresh(productId)

View File

@ -190,22 +190,7 @@ function setInitialGlobalState(Grocy)
var link = $(e.currentTarget).attr("href");
bootbox.dialog({
message: '<iframe height="650px" class="embed-responsive" src="' + link + '"></iframe>',
size: 'large',
backdrop: true,
closeButton: false,
buttons: {
cancel: {
label: __t('Close'),
className: 'btn-secondary responsive-button',
callback: function()
{
bootbox.hideAll();
}
}
}
});
Grocy.OpenSubView(link);
});
// serializeJSON defaults

View File

@ -13,6 +13,8 @@ import { animateCSS, BoolVal, EmptyElementWhenMatches } from "./helpers/extensio
import Translator from "gettext-translator";
import { WindowMessageBag } from './helpers/messagebag';
import * as components from './components';
import * as uuid from 'uuid';
import { GrocyProxy } from "./lib/proxy";
import "./helpers/string";
@ -54,6 +56,8 @@ class GrocyClass
this.initComponents = [];
this.RootGrocy = null;
this.documentReady = false;
this.preloadViews = [];
// Init some classes
this.Api = new GrocyApi(this);
@ -114,6 +118,18 @@ class GrocyClass
}
});
}
$(document).on('ready', () =>
{
this.documentReady = true;
var element = self.preloadViews.pop();
while (element !== undefined)
{
self.preloadViews(element.viewName, element.loadCss, element.cb);
element = self.preloadViews.pop();
}
})
}
static createSingleton(config, view)
@ -240,11 +256,19 @@ class GrocyClass
}
}
LoadView(viewName, scope = null)
LoadView(viewName, scope = null, grocy = null)
{
if (Object.prototype.hasOwnProperty.call(window, viewName + "View"))
{
window[viewName + "View"](this, scope);
if (scope != null && grocy == null)
{
console.warn("scoped view set but non-scoped grocy is used. Results are undefined!");
}
if (scope == null)
{
grocy = this;
}
window[viewName + "View"](grocy, scope);
}
else
{
@ -254,6 +278,12 @@ class GrocyClass
PreloadView(viewName, loadCSS = false, cb = () => { })
{
if (!this.documentReady)
{
this.preloadViews.push({ viewName: viewName, loadCss: loadCss, cb: cb });
return;
}
if (!Object.prototype.hasOwnProperty.call(window, viewName + "View"))
{
$.ajax({
@ -277,6 +307,46 @@ class GrocyClass
}
}
OpenSubView(link)
{
var self = this;
$.ajax({
dataType: "json",
link,
success: (data) =>
{
let scopeId = uuid.v4()
var proxy = new GrocyProxy(this, "#" + scopeId, data.config, link);
bootbox.dialog({
message: '<div id="' + scopeId + '">' + data.template + '</div>',
size: 'large',
backdrop: true,
closeButton: false,
buttons: {
cancel: {
label: self.translate('Close'),
className: 'btn-secondary responsive-button',
callback: function()
{
proxy.Unload();
bootbox.hideAll();
}
}
},
onShow: () =>
{
// dialog div is alive, init view.
// this occurs before the view is shown.
self.LoadView(data.viewJsName, "#" + scopeId, proxy);
}
});
}
})
}
UndoStockBooking(bookingId)
{
var self = this;

View File

@ -31,12 +31,20 @@ class GrocyProxy
// scoping
this.scopeSelector = scopeSelector;
this.scope = $(scope);
this.$scope = this.scope.find;
this.scope = $(scopeSelector);
var jScope = this.scope;
this.$scope = (selector) => jScope.find(selector);
var queryString = url.split('?', 2);
this.virtualUrl = queryString.length == 2 ? queryString[1] : ""; // maximum two parts
this.config = config;
if (Object.prototype.hasOwnProperty.call(this.config, "UserSettings"))
{
// if we need to override UserSettings, we need to copy the object.
// not great, but eh.
Object.assign(this.config.UserSettings, RootGrocy.UserSettings);
this.UserSettings = config.UserSettings;
}
this.configProxy = Proxy.revocable(this.config, {
get: function(target, prop, receiver)
@ -47,7 +55,7 @@ class GrocyProxy
}
else
{
return Reflect.get(rootGrocy.config, prop, target);
return Reflect.get(RootGrocy.config, prop, target);
}
}
})
@ -130,10 +138,10 @@ class GrocyProxy
UpdateUriParam(key, value)
{
params = {}
var params = {}
var vars = this.virtualUrl.split("&");
for (part of vars)
for (let part of vars)
{
var lkey, lvalue;
[lkey, lvalue = null] = part.split('=');
@ -144,6 +152,7 @@ class GrocyProxy
params[key] = value;
var vurl = ""
for ([key, value] of params)
{
vurl += "&" + key
@ -157,10 +166,10 @@ class GrocyProxy
RemoveUriParam(key)
{
params = {}
var params = {}
var vars = this.virtualUrl.split("&");
for (part of vars)
for (let part of vars)
{
var lkey, lvalue;
[lkey, lvalue = null] = part.split('=');
@ -172,6 +181,7 @@ class GrocyProxy
}
var vurl = ""
let value;
for ([key, value] of params)
{
vurl += "&" + key

View File

@ -6,6 +6,12 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
top.on('load', () =>
{
Grocy.PreloadView("batteryform");
});
var batteriesTable = $scope('#batteries-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -8,6 +8,13 @@
var batterycard = Grocy.Use("batterycard");
// preload some views.
top.on('load', () =>
{
Grocy.PreloadView("batteriesjournal");
Grocy.PreloadView("batteryform");
});
var batteriesOverviewTable = $scope('#batteries-overview-table').DataTable({
'order': [[4, 'asc']],
'columnDefs': [

View File

@ -10,6 +10,12 @@
var chorecard = Grocy.Use("chorecard");
// preload some views.
top.on('load', () =>
{
Grocy.PreloadView("choresjournal");
});
var choresOverviewTable = $scope('#chores-overview-table').DataTable({
'order': [[2, 'asc']],
'columnDefs': [

View File

@ -6,6 +6,12 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
top.on('load', () =>
{
Grocy.PreloadView("locationform");
});
var locationsTable = $scope('#locations-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -11,6 +11,13 @@ function productformView(Grocy, scope = null)
}
Grocy.Use("numberpicker");
// preload some views.
top.on('load', () =>
{
Grocy.PreloadView("productgroupform");
});
var shoppinglocationpicker = Grocy.Use("shoppinglocationpicker");
var userfields = Grocy.Use("userfieldsform");
var productpicker = Grocy.Use("productpicker");

View File

@ -6,6 +6,10 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("productgroupform");
var groupsTable = $scope('#productgroups-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -10,6 +10,11 @@ function quantityunitformView(Grocy, scope = null)
var userfields = Grocy.Use("userfieldsform");
// preload some views.
Grocy.PreloadView("quantityunitconversionform");
$scope('.save-quantityunit-button').on('click', function(e)
{
e.preventDefault();

View File

@ -15,6 +15,12 @@ function shoppinglistView(Grocy, scope = null)
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("shoppinglistform");
Grocy.PreloadView("shoppinglistitemform");
Grocy.Use("calendarcard");
var productcard = Grocy.Use("productcard");

View File

@ -6,6 +6,11 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("shoppinglocationform");
var locationsTable = $scope('#shoppinglocations-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -11,6 +11,19 @@
var productcard = Grocy.Use("productcard");
var productpicker = Grocy.Use("productpicker");
// preload some views.
Grocy.PreloadView("stockentryform");
Grocy.PreloadView("shoppinglistitemform");
Grocy.PreloadView("purchase");
Grocy.PreloadView("conusme");
Grocy.PreloadView("inventory");
Grocy.PreloadView("stockjournal");
Grocy.PreloadView("stockjournalsummary");
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
Grocy.PreloadView("transfer");
var stockEntriesTable = $scope('#stockentries-table').DataTable({
'order': [[2, 'asc']],
'columnDefs': [

View File

@ -9,6 +9,19 @@
var productcard = Grocy.Use("productcard");
// preload some views.
Grocy.PreloadView("stockentries");
Grocy.PreloadView("shoppinglistitemform");
Grocy.PreloadView("purchase");
Grocy.PreloadView("conusme");
Grocy.PreloadView("inventory");
Grocy.PreloadView("stockjournal");
Grocy.PreloadView("stockjournalsummary");
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
Grocy.PreloadView("transfer");
var stockOverviewTable = $scope('#stock-overview-table').DataTable({
'order': [[5, 'asc']],
'columnDefs': [

View File

@ -6,6 +6,11 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("taskcategoryform");
var categoriesTable = $scope('#taskcategories-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -8,6 +8,10 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("taskform");
var tasksTable = $scope('#tasks-table').DataTable({
'order': [[2, 'asc']],
'columnDefs': [

View File

@ -5,6 +5,9 @@
{
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("userentityform")
var userentitiesTable = $scope('#userentities-table').DataTable({
'order': [[1, 'asc']],

View File

@ -6,6 +6,10 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("userfieldform");
var userfieldsTable = $scope('#userfields-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -6,6 +6,10 @@
$scope = (scope) => $(scope).find(scope);
}
// preload some views.
Grocy.PreloadView("userobjectform");
var userobjectsTable = $scope('#userobjects-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [

View File

@ -13,7 +13,7 @@
"@fullcalendar/timegrid": "4.4.2",
"@rollup/plugin-eslint": "^8.0.1",
"animate.css": "^3.7.2",
"bootbox": "^5.3.2",
"bootbox": "^5.5.2",
"bootstrap": "^4.5.2",
"bootstrap-select": "^1.13.18",
"bwip-js": "^3.0.1",

View File

@ -1847,7 +1847,7 @@ __metadata:
languageName: node
linkType: hard
"bootbox@npm:^5.3.2":
"bootbox@npm:^5.5.2":
version: 5.5.2
resolution: "bootbox@npm:5.5.2"
dependencies:
@ -4709,7 +4709,7 @@ fsevents@~2.3.2:
autoprefixer: ^10.2.6
babel-core: ^6.26.3
babel-preset-es2015: ^6.24.1
bootbox: ^5.3.2
bootbox: ^5.5.2
bootstrap: ^4.5.2
bootstrap-select: ^1.13.18
browserslist: ^4.16.6