getGlobalEvents method
Retrieves global events and parameters for rendering.
Constructs a map of global events and parameters for rendering purposes. This includes configuration values, asset URLs, session data, and more.
Returns a Map<String, Object?> with global parameters and events.
Implementation
Map<String, Object?> getGlobalEvents() {
Map<String, Object?> params = {};
params['isLocalDebug'] = WaServer.config.isLocalDebug;
params['assets'] = {
'js': () {
if (jsRenderId.isNotEmpty) return jsRenderId;
jsRenderId = "<#DART-SERVER#>JS<#DART-SERVER#>";
return jsRenderId;
},
'css': () {
if (cssRenderId.isNotEmpty) return cssRenderId;
cssRenderId = "<#DART-SERVER#>CSS<#DART-SERVER#>";
return cssRenderId;
},
'dataJs': () {
if (dataJsId.isNotEmpty) return dataJsId;
dataJsId = "<#DART-SERVER#>JS-DATA<#DART-SERVER#>";
return dataJsId;
//assetManager.getDataJs();
},
};
params['render'] = () => 'TODO';
params['data'] = getAllData();
params['session'] = getAllSession();
params['param'] = (String path) {
return _params.getByPathString(path, def: '');
};
params['validator'] = (String path) {
return getValidator().navigation<Object>(
path: path,
def: '',
);
};
var events = {
'route': route == null ? '/' : route!.getPathRender(),
'uri': Uri.encodeComponent(_rq.requestedUri.toString()),
'path': Uri.encodeComponent(_rq.requestedUri.path),
'pathString': _rq.requestedUri.path,
'isPath': (String path) {
return pathsEqual([_rq.requestedUri.path, path]);
},
'endpoint': endpoint,
'url': (String path) {
return url(path);
},
'urlToLanguage': (String language) {
var res = '';
if (_rq.requestedUri.pathSegments.isNotEmpty &&
_rq.requestedUri.pathSegments[0] == language) {
res = url(_rq.requestedUri.path);
} else if (_rq.requestedUri.pathSegments.isNotEmpty &&
_rq.requestedUri.pathSegments[0] == getLanguage()) {
var paths = _rq.requestedUri.pathSegments.sublist(1);
res = url('/$language/${paths.join('/')}');
} else {
res = url('/$language${_rq.requestedUri.path}');
}
res = Uri.decodeFull(uri.replace(path: res).toString());
return res;
},
'urlParam': (String path, Map<String, String> params) {
return url(path, params: params);
},
'getCookie': (String key, [String def = '']) {
return getCookie(key, def: def);
},
'ln': getLanguage(),
'dir': 'language.${getLanguage()}_dir'.tr.write(this),
'langs': () {
var langs = WaServer.appLanguages.keys;
var result = [];
for (var lang in langs) {
result.add({
'code': lang,
'label': 'language.${lang}_label'.tr.write(this),
'contry': 'language.${lang}_contry'.tr.write(this),
});
}
return result;
},
'pageTitle': route != null && route!.title.isNotEmpty
? route!.title
: 'pages.title'.tr.write(this),
'setting': _setting,
'formChecker': ([String? name]) => formChecker(name: name),
};
params['\$e'] = LMap(events, def: null);
params['\$n'] = (String path) {
return getParams().navigation<Object>(path: path, def: '');
};
params['\$l'] = LMap(localEvents, def: null);
params['\$t'] = (String text, [Object? params]) {
if (params == null) {
return text.tr.write(this);
} else {
var json = WaJson.tryJson<String, Object?>(params);
if (json != null) {
return text.tr.write(this, json);
}
}
return text.tr.write(this);
};
addParam('timestamp_end', DateTime.now().millisecondsSinceEpoch);
var duration = (getParam('timestamp_end', def: 0) as int) -
(getParam('timestamp_start', def: 0) as int);
addParam('duration', duration);
var lmap = LMap(params, def: null);
params['\$'] = lmap;
return params;
}