Skip to content

Commit

Permalink
Merge 0312c85 into 8e2bba7
Browse files Browse the repository at this point in the history
  • Loading branch information
peuter committed May 7, 2020
2 parents 8e2bba7 + 0312c85 commit ec0c130
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"devDependencies": {
"@babel/polyfill": "^7.8.7",
"@qooxdoo/compiler": "^1.0.0-beta.20200502-0822",
"@qooxdoo/compiler": "^1.0.0-beta.20200507-1713",
"csso": "^3.5.1",
"easyimage": "^3.1.1",
"fast-glob": "^3.2.2",
Expand Down
4 changes: 3 additions & 1 deletion source/class/cv/ui/manager/editor/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ qx.Class.define('cv.ui.manager.editor.Config', {
},

_onModelValueChange: function (ev) {
this.setContent(ev.getData());
if (this.getFile()) {
this.setContent(ev.getData());
}
},

// overridden
Expand Down
93 changes: 90 additions & 3 deletions source/class/cv/ui/manager/editor/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ qx.Class.define('cv.ui.manager.editor.Source', {
COUNTER: 0,
MONACO_EXTENSION_REGEX: null,
SUPPORTED_FILES: function (file) {
if (file.getName() === 'hidden.php') {
return false
} else if (window.monaco && window.monaco.languages) {
if (window.monaco && window.monaco.languages) {
if (!cv.ui.manager.editor.Source.MONACO_EXTENSION_REGEX) {
// monaco has already been loaded, we can use its languages configuration to check if this file is supported
var extensions = []
Expand Down Expand Up @@ -131,6 +129,7 @@ qx.Class.define('cv.ui.manager.editor.Source', {
_basePath: null,
_workerWrapper: null,
_currentDecorations: null,
_configClient: null,

_initWorker: function () {
this._workerWrapper = cv.ui.manager.editor.Worker.getInstance();
Expand Down Expand Up @@ -166,6 +165,27 @@ qx.Class.define('cv.ui.manager.editor.Source', {
},
theme: 'vs-dark'
});
var baseVersion = cv.Version.VERSION.split('-')[0];
var xhr = new qx.io.request.Xhr(qx.util.ResourceManager.getInstance().toUri("hidden-schema.json"));
xhr.set({
method: "GET",
accept: "application/json"
});
xhr.addListenerOnce("success", function (e) {
var req = e.getTarget();
var schema = req.getResponse();
window.monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
allowComments: true,
schemas: [{
uri: "https://www.cometvisu.org/CometVisu/schemas/" + baseVersion + "/hidden-schema.json",
fileMatch: ["hidden.php"],
schema: schema
}]
})
}, this);
xhr.send();

if (this.getFile()) {
this._loadFile(this.getFile());
}
Expand Down Expand Up @@ -208,6 +228,51 @@ qx.Class.define('cv.ui.manager.editor.Source', {
}
},

_loadFromFs: function () {
if (this.getFile().getName() === 'hidden.php') {
if (!this._configClient) {
this._configClient = cv.io.rest.Client.getConfigClient();
this._configClient.addListener('getSuccess', function (ev) {
this.setContent(JSON.stringify(ev.getData(), null, 2));
}, this);
this._configClient.addListener('updateSuccess', this._onSaved, this);
}
this._configClient.get({section: '*', key: '*'});
} else {
this.base(arguments);
}
},

save: function (callback, overrideHash) {
if (this.getFile().getName() === 'hidden.php') {
if (!this.getFile().isValid()) {
cv.ui.manager.snackbar.Controller.error(this.tr('Hidden config is invalid, please correct the errors'));
} else if (this.getFile().getHasWarnings()) {
// ask user if he really want to save a file with warnings
dialog.Dialog.confirm(this.tr("Hidden config content has some warnings! It is recommended to fix the warnings before saving. Save anyways?"), function (confirmed) {
if (confirmed) {
this.__saveHiddenConfig();
}
}, this, qx.locale.Manager.tr('Confirm saving with warnings'));
} else {
this.__saveHiddenConfig();
}
} else {
this.base(arguments, callback, overrideHash);
}
},

__saveHiddenConfig: function () {
this._configClient.saveSync(null, JSON.parse(this.getCurrentContent()), function (err) {
if (err) {
cv.ui.manager.snackbar.Controller.error(this.tr('Saving hidden config failed with error %1 (%2)', err.status, err.statusText));
} else {
cv.ui.manager.snackbar.Controller.info(this.tr('Hidden config has been saved'));
this._onSaved();
}
}, this);
},

_applyContent: function(value) {
var file = this.getFile();
if (!file) {
Expand All @@ -224,6 +289,23 @@ qx.Class.define('cv.ui.manager.editor.Source', {
value = value.documentElement.outerHTML;
}
newModel = window.monaco.editor.createModel(value, this._getLanguage(file), file.getUri());
newModel.onDidChangeDecorations(function (ev) {
var errors = false;
var warnings = false;
monaco.editor.getModelMarkers({
owner: newModel.getModeId(),
resource: file.getUri()
}).some(function (marker) {
if (marker.severity === monaco.MarkerSeverity.Warning) {
warnings = true;
} else if (marker.severity === monaco.MarkerSeverity.Error) {
errors = true;
}
return warnings && errors;
}, this);
file.setValid(!errors);
file.setHasWarnings(warnings);
})
}

if (model !== newModel) {
Expand Down Expand Up @@ -327,6 +409,10 @@ qx.Class.define('cv.ui.manager.editor.Source', {
},

_getLanguage: function (file) {
if (file.getName() === 'hidden.php') {
// override this setting as we are loading the hidden config from its REST endpoint as JSON
return 'json';
}
var type = file.getName().split('.').pop();
switch (type) {
case 'svg':
Expand Down Expand Up @@ -363,6 +449,7 @@ qx.Class.define('cv.ui.manager.editor.Source', {
this._editor.dispose();
this._editor = null;
}
this._configClient = null;
qx.ui.core.FocusHandler.getInstance().setUseTabNavigation(true);
}
});
9 changes: 9 additions & 0 deletions source/class/cv/ui/manager/model/FileItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ qx.Class.define('cv.ui.manager.model.FileItem', {
event: 'changeValid'
},

/**
* The validation of this files content found some warnings
*/
hasWarnings: {
check: 'Boolean',
init: false,
event: 'changeHasWarnings'
},

/**
* Temporary content to show, e.g. for new files, when there is no 'real' file with content yet to request from the backend
* this content should be shown
Expand Down
24 changes: 24 additions & 0 deletions source/resource/hidden-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/schema#",
"$id": "https://www.cometvisu.org/CometVisu/schemas/0.12/hidden-schema.json",

"type": "object",
"patternProperties": {
"^fritzbox(\\..*)?$": { "$ref": "#/definitions/login" },
"^influx(\\..*)?$": { "$ref": "#/definitions/login" },
"^tr064(\\..*)?$": { "$ref": "#/definitions/login" }
},
"definitions": {
"login": {
"type": "object",
"properties": {
"uri": { "type": "string", "format": "uri" },
"user": { "type": "string" },
"pass": { "type": "string" },
"selfsigned": { "type": "string", "enum": ["true", "false"] }
},
"required": ["uri", "user", "pass"],
"additionalProperties": false
}
}
}
5 changes: 3 additions & 2 deletions source/rest/manager/src/Api/ConfigApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ protected function load()
}

protected function dump() {
$out = '
<?php
$out = '<?php
// File for configurations that shouldn\'t be shared with the user
$data = \'' . json_encode($this->hidden, JSON_PRETTY_PRINT) . '\';
$hidden = json_decode($data, true);
Expand Down Expand Up @@ -130,6 +129,8 @@ public function getHiddenConfig(ServerRequestInterface $request, ResponseInterfa
public function saveHiddenConfig(ServerRequestInterface $request, ResponseInterface $response, array $args)
{
$this->hidden = $request->getParsedBody();
var_dump($request->getParsedBody());
var_dump($request->getBody());
try {
$this->dump();
} catch (Exception $e) {
Expand Down
3 changes: 2 additions & 1 deletion utils/compile/cv/CompileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { CvBuildTarget } = require('./BuildTarget')
// we add them here
const additionalResources = [
'visu_config.xsd',
'hidden-schema.json',
'cometvisu_management.css',
'config/visu_config*.xml',
'config/hidden.php'
Expand Down Expand Up @@ -38,7 +39,7 @@ class CvCompileHandler extends AbstractCompileHandler {
onLoad() {
super.onLoad();
const command = this._compilerApi.getCommand();
if (this._config.targetType === 'build' || command instanceof qx.tool.cli.commands.Deploy) {
if (this._config.targetType === 'build') {// || command instanceof qx.tool.cli.commands.Deploy) {
this._config.targets.some(target => {
if (target.type === 'build') {
target.targetClass = CvBuildTarget
Expand Down
4 changes: 4 additions & 0 deletions utils/travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ grunt update-demo-config
rm -rf out/de/$VERSION_PATH/demo
mv compiled/build out/de/$VERSION_PATH/demo

echo "copying JSON schema for hidden configuration"
mkdir -p out/schemas/$VERSION_PATH/
cp source/resource/hidden-schema.json out/schemas/$VERSION_PATH/

# Copy demo-mode to default config
cp out/de/$VERSION_PATH/demo/resource/demo/visu_config_demo_testmode.xml out/de/$VERSION_PATH/demo/resource/config/visu_config.xml

Expand Down

0 comments on commit ec0c130

Please sign in to comment.