Skip to content

Commit

Permalink
more work on the settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlen22 committed Mar 14, 2018
1 parent cd0bfb8 commit 059b303
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 40 deletions.
29 changes: 18 additions & 11 deletions assets/static/settings-page.js
Expand Up @@ -2,14 +2,14 @@ angular.module('settings', []).config(function ($locationProvider) {
$locationProvider.html5Mode(false).hashPrefix('*');
}).run(function ($templateCache) {
var templates = {
string: `<input type="text" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
number: `<input type="number" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
boolean: `<input type="checkbox" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
string: `<input type="text" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
number: `<input type="number" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
boolean: `<input type="checkbox" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
enum: `
<select name="{{item.name}}" value="" ng-disabled="readonly"}
ng-model="outputs[item.name]"
ng-options="k for k in item.valueOptions[1]">
</select> {{description}}
</select> <span ng-bind-html="description"></span>
`,
hashmapenum: `
<fieldset>
Expand All @@ -18,10 +18,11 @@ angular.module('settings', []).config(function ($locationProvider) {
ng-controller="HashmapEnumItemCtrl"
ng-include="'template-' + item.valueType"></div>
</fieldset>`,
subpage: `Please go to <a href="{{item.name}}">{{item.name}}</a> for details on changing this setting`,
function: `
<ng-include src="'template-function' + item.name"></ng-include>
`,
functiontree: ``,
functiontypes: `Coming soon`,
settingsPage: `
<fieldset ng-repeat="(i, item) in data" ng-controller="SettingsPageItemCtrl">
<legend>{{item.name}}</legend>
Expand All @@ -32,7 +33,7 @@ angular.module('settings', []).config(function ($locationProvider) {
for (var i in templates) {
$templateCache.put("template-" + i, templates[i]);
}
}).controller("HashmapEnumItemCtrl", function ($scope) {
}).controller("HashmapEnumItemCtrl", function ($scope, $sce) {
let parentItem = $scope.item;
if (parentItem.valueType !== "hashmapenum")
return;
Expand All @@ -44,9 +45,15 @@ angular.module('settings', []).config(function ($locationProvider) {
if (typeof $scope.outputs[parentItem.name] !== "object")
$scope.outputs[parentItem.name] = {};
$scope.outputs = $scope.outputs[parentItem.name];
$scope.description = $scope.description[parentItem.name];
}).controller("SettingsPageItemCtrl", function ($scope) {
$scope.description = $scope.description[$scope.key];
if (typeof $scope.description === "string") {
$scope.description = $sce.trustAsHtml($scope.description);
}
}).controller("SettingsPageItemCtrl", function ($scope, $sce) {
$scope.description = $scope.description[$scope.item.name];
if (typeof $scope.description === "string") {
$scope.description = $sce.trustAsHtml($scope.description);
}
}).controller("SettingsPageCtrl", function ($scope) {
$scope.outputs = {
"tree": {
Expand Down Expand Up @@ -86,7 +93,7 @@ angular.module('settings', []).config(function ($locationProvider) {
}
};
$scope.data = [
{ type: 2, name: "tree", valueType: "function", },
{ type: 2, name: "tree", valueType: "subpage", },
{ type: 0, name: "types", valueType: "function", },
{ type: 1, name: "host", valueType: "string" },
{ type: 1, name: "port", valueType: "number" },
Expand Down Expand Up @@ -127,8 +134,8 @@ angular.module('settings', []).config(function ($locationProvider) {
mkdir: "Allow network users to create directories and datafolders.",
upload: "Allow network users to upload files.",
settings: "Allow network users to change non-critical settings.",
WARNING_all_settings_WARNING: "Allow network users to change critical settings: <br/>"
+ `<pre>${$scope.data.filter(e => e.type > 0).map(e => e.name).join(', ')}</pre>`
WARNING_all_settings_WARNING: "Allow network users to change critical settings: "
+ `<code>${$scope.data.filter(e => e.type > 0).map(e => e.name).join(', ')}</code>`
},
maxAge: "",
tsa: "",
Expand Down
29 changes: 18 additions & 11 deletions assets/static/settings-page.ts
Expand Up @@ -40,14 +40,14 @@ angular.module('settings', [
$locationProvider.html5Mode(false).hashPrefix('*');
}).run(function ($templateCache) {
var templates = {
string: `<input type="text" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
number: `<input type="number" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
boolean: `<input type="checkbox" name="{{item.name}}" ng-model="outputs[item.name]"/>`,
string: `<input type="text" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
number: `<input type="number" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
boolean: `<input type="checkbox" name="{{item.name}}" ng-model="outputs[item.name]"/> <span ng-bind-html="description"></span>`,
enum: `
<select name="{{item.name}}" value="" ng-disabled="readonly"}
ng-model="outputs[item.name]"
ng-options="k for k in item.valueOptions[1]">
</select> {{description}}
</select> <span ng-bind-html="description"></span>
`,
hashmapenum: `
<fieldset>
Expand All @@ -56,10 +56,11 @@ angular.module('settings', [
ng-controller="HashmapEnumItemCtrl"
ng-include="'template-' + item.valueType"></div>
</fieldset>`,
subpage: `Please go to <a href="{{item.name}}">{{item.name}}</a> for details on changing this setting`,
function: `
<ng-include src="'template-function' + item.name"></ng-include>
`,
functiontree: ``,
functiontypes: `Coming soon`,
settingsPage: `
<fieldset ng-repeat="(i, item) in data" ng-controller="SettingsPageItemCtrl">
<legend>{{item.name}}</legend>
Expand All @@ -71,7 +72,7 @@ angular.module('settings', [
for (var i in templates) {
$templateCache.put("template-" + i, templates[i]);
}
}).controller("HashmapEnumItemCtrl", function ($scope) {
}).controller("HashmapEnumItemCtrl", function ($scope, $sce: angular.ISCEService) {
let parentItem: SettingsPageItem & ValueType = $scope.item;
if (parentItem.valueType !== "hashmapenum") return;
$scope.item = {
Expand All @@ -82,9 +83,15 @@ angular.module('settings', [
if (typeof $scope.outputs[parentItem.name] !== "object")
$scope.outputs[parentItem.name] = {};
$scope.outputs = $scope.outputs[parentItem.name];
$scope.description = $scope.description[parentItem.name];
}).controller("SettingsPageItemCtrl", function ($scope) {
$scope.description = $scope.description[$scope.key];
if(typeof $scope.description === "string"){
$scope.description = $sce.trustAsHtml($scope.description);
}
}).controller("SettingsPageItemCtrl", function ($scope, $sce: angular.ISCEService) {
$scope.description = $scope.description[$scope.item.name];
if(typeof $scope.description === "string"){
$scope.description = $sce.trustAsHtml($scope.description);
}
}).controller("SettingsPageCtrl", function ($scope) {
$scope.outputs = {
"tree": {
Expand Down Expand Up @@ -124,7 +131,7 @@ angular.module('settings', [
}
};
$scope.data = [
{ type: 2, name: "tree", valueType: "function", /* valueOptions: [treeGenerate] */ },
{ type: 2, name: "tree", valueType: "subpage", /* valueOptions: [treeGenerate] */ },
{ type: 0, name: "types", valueType: "function", /* valueOptions: [typesFunction] */ },
{ type: 1, name: "host", valueType: "string" },
{ type: 1, name: "port", valueType: "number" },
Expand Down Expand Up @@ -168,8 +175,8 @@ angular.module('settings', [
mkdir: "Allow network users to create directories and datafolders.",
upload: "Allow network users to upload files.",
settings: "Allow network users to change non-critical settings.",
WARNING_all_settings_WARNING: "Allow network users to change critical settings: <br/>"
+ `<pre>${$scope.data.filter(e => e.type > 0).map(e => e.name).join(', ')}</pre>`
WARNING_all_settings_WARNING: "Allow network users to change critical settings: "
+ `<code>${$scope.data.filter(e => e.type > 0).map(e => e.name).join(', ')}</code>`
},
maxAge: "",
tsa: "",
Expand Down
8 changes: 4 additions & 4 deletions src/generateSettingsPage.js
Expand Up @@ -19,8 +19,8 @@ function initSettingsRequest(e) {
}
exports.initSettingsRequest = initSettingsRequest;
const data = [
{ type: 2, name: "tree", valueType: "function", },
{ type: 0, name: "types", valueType: "function", },
{ type: 2, name: "tree", valueType: "subpage", valueOptions: { handler: (state) => { } } },
{ type: 0, name: "types", valueType: "function" },
{ type: 1, name: "host", valueType: "string" },
{ type: 1, name: "port", valueType: "number" },
{ type: 1, name: "username", valueType: "string" },
Expand Down Expand Up @@ -60,8 +60,8 @@ const descriptions = {
mkdir: "Allow network users to create directories and datafolders.",
upload: "Allow network users to upload files.",
settings: "Allow network users to change non-critical settings.",
WARNING_all_settings_WARNING: "Allow network users to change critical settings: <br/>"
+ `<pre>${data.filter(e => e.type > 0).map(e => e.name).join(', ')}</pre>`
WARNING_all_settings_WARNING: "Allow network users to change critical settings: "
+ `<code>${data.filter(e => e.type > 0).map(e => e.name).join(', ')}</code>`
},
maxAge: "",
tsa: "",
Expand Down
38 changes: 24 additions & 14 deletions src/generateSettingsPage.ts
Expand Up @@ -23,21 +23,31 @@ type SettingsPageItem = {
// valueType: string,
// valueOptions?: any[]
};
type ValueType = {
type ValueType_function = {
valueType: "function",
// valueOptions: [(defValue: any, keys: string[], readOnly: boolean, description: any) => string]
} | {
valueType: "string" | "number" | "boolean"
} | {
valueType: "enum",
valueOptions: ["number" | "string", (number | string)[]]
} | {
valueType: "hashmapenum",
valueOptions: [("string" | "number" | "boolean")[], string[]]
} & SettingsPageItem;
type ValueType_primitive = {
valueType: "string" | "number" | "boolean"
} & SettingsPageItem;
type ValueType_enum = {
valueType: "enum",
valueOptions: ["number" | "string", (number | string)[]]
} & SettingsPageItem;
type ValueType_hashmapenum = {
valueType: "hashmapenum",
valueOptions: [("string" | "number" | "boolean")[], string[]]
} & SettingsPageItem;
type ValueType_subpage = {
valueType: "subpage",
valueOptions: {
handler: (state: StateObject) => void;
}
const data: (SettingsPageItem & ValueType)[] = [
{ type: 2, name: "tree", valueType: "function", /* valueOptions: [treeGenerate] */ },
{ type: 0, name: "types", valueType: "function", /* valueOptions: [typesFunction] */ },
} & SettingsPageItem;
type SettingsPageItemTypes = ValueType_function | ValueType_enum | ValueType_hashmapenum | ValueType_primitive | ValueType_subpage;
const data: (SettingsPageItemTypes)[] = [
{ type: 2, name: "tree", valueType: "subpage", valueOptions: { handler: (state) => { } } },
{ type: 0, name: "types", valueType: "function" },
{ type: 1, name: "host", valueType: "string" },
{ type: 1, name: "port", valueType: "number" },
{ type: 1, name: "username", valueType: "string" },
Expand Down Expand Up @@ -81,8 +91,8 @@ const descriptions: {[K in keyof ServerConfig]: any} = {
mkdir: "Allow network users to create directories and datafolders.",
upload: "Allow network users to upload files.",
settings: "Allow network users to change non-critical settings.",
WARNING_all_settings_WARNING: "Allow network users to change critical settings: <br/>"
+ `<pre>${data.filter(e => e.type > 0).map(e => e.name).join(', ')}</pre>`
WARNING_all_settings_WARNING: "Allow network users to change critical settings: "
+ `<code>${data.filter(e => e.type > 0).map(e => e.name).join(', ')}</code>`
},
maxAge: "",
tsa: "",
Expand Down

0 comments on commit 059b303

Please sign in to comment.