You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by zr...@apache.org on 2024/12/18 09:26:06 UTC
(trafficcontrol) branch master updated: Add comment field to parameters (#7845)
This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new be68eef0df Add comment field to parameters (#7845)
be68eef0df is described below
commit be68eef0df12b12a48cb6b308033eec68c16c6f7
Author: The Anh Nguyen <nt...@gmail.com>
AuthorDate: Wed Dec 18 16:25:59 2024 +0700
Add comment field to parameters (#7845)
* add comment field parameter
* add comment into parameter
* update Changelog
* fix data search value
* add comment to Parameter struct
* add Comment in test
* add Comment test system info
* Add show/hide comment field in properties
* update migration
* chore: update migration files name
---
CHANGELOG.md | 1 +
lib/go-tc/parameters.go | 4 +++
...2024121808014200_add_comment_parameter.down.sql | 18 ++++++++++++
.../2024121808014200_add_comment_parameter.up.sql | 18 ++++++++++++
.../traffic_ops_golang/parameter/parameters.go | 32 +++++++++++++++-------
.../parameter/parameters_test.go | 4 +++
.../systeminfo/system_info_test.go | 5 ++++
traffic_portal/.gitignore | 1 +
.../modules/form/parameter/form.parameter.tpl.html | 8 ++++++
.../table/parameters/TableParametersController.js | 15 ++++++++--
.../table/parameters/table.parameters.tpl.html | 4 ++-
.../app/src/traffic_portal_properties.json | 7 +++++
12 files changed, 103 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index abdf411652..b03cb10fa6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added
- [#8014](https://github.com/apache/trafficcontrol/pull/8014) *Traffic Ops* Added logs to indicate which mechanism a client used to login to TO.
- [#7812](https://github.com/apache/trafficcontrol/pull/7812) *Traffic Portal*: Expose the `configUpdateFailed` and `revalUpdateFailed` fields on the server table.
+- [#7845](https://github.com/apache/trafficcontrol/pull/7845) *Traffic Ops, Traffic Portal*: Add `comment` field to parameters
- [#7870](https://github.com/apache/trafficcontrol/pull/7870) *Traffic Portal*: Adds a hyperlink to the DSR page to the DS itself for ease of navigation.
- [#7896](https://github.com/apache/trafficcontrol/pull/7896) *ATC Build system*: Count commits since the last release, not commits
- [#7927](https://github.com/apache/trafficcontrol/pull/7927) *Traffic Stats*: Migrate dynamic scripted Grafana Dashboards to Scenes
diff --git a/lib/go-tc/parameters.go b/lib/go-tc/parameters.go
index 3abc19e884..ebd887f162 100644
--- a/lib/go-tc/parameters.go
+++ b/lib/go-tc/parameters.go
@@ -53,6 +53,7 @@ type Parameter struct {
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure bool `json:"secure" db:"secure"`
Value string `json:"value" db:"value"`
+ Comment string `json:"comment" db:"comment"`
}
// ParameterNullable is exactly like Parameter except that its properties are
@@ -68,6 +69,7 @@ type ParameterNullable struct {
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure *bool `json:"secure" db:"secure"`
Value *string `json:"value" db:"value"`
+ Comment *string `json:"comment" db:"comment"`
}
// ParametersResponseV5 is an alias for the latest minor version for the major version 5.
@@ -95,6 +97,7 @@ type ParameterV50 struct {
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure bool `json:"secure" db:"secure"`
Value string `json:"value" db:"value"`
+ Comment string `json:"comment" db:"comment"`
}
// ParameterNullableV5 is an alias for the latest minor version for the major version 5.
@@ -113,6 +116,7 @@ type ParameterNullableV50 struct {
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure *bool `json:"secure" db:"secure"`
Value *string `json:"value" db:"value"`
+ Comment *string `json:"comment" db:"comment"`
}
// ProfileParameterByName is a structure that's used to represent a Parameter
diff --git a/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql
new file mode 100644
index 0000000000..fd50f31b40
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.down.sql
@@ -0,0 +1,18 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+ALTER TABLE public.parameter DROP column comment;
diff --git a/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql
new file mode 100644
index 0000000000..66d28c045a
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2024121808014200_add_comment_parameter.up.sql
@@ -0,0 +1,18 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+ALTER TABLE public.parameter ADD COLUMN IF NOT EXISTS comment text;
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go
index e447407999..6e3ae88dc5 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go
@@ -48,6 +48,7 @@ const (
ConfigFileQueryParam = "configFile"
IDQueryParam = "id"
ValueQueryParam = "value"
+ CommentQueryParam = "comment"
)
var (
@@ -86,6 +87,7 @@ func (v *TOParameter) ParamColumns() map[string]dbhelpers.WhereColumnInfo {
NameQueryParam: {Column: "p.name"},
SecureQueryParam: {Column: "p.secure", Checker: api.IsBool},
ValueQueryParam: {Column: "p.value"},
+ CommentQueryParam: {Column: "p.comment"},
}
}
func (v *TOParameter) UpdateQuery() string { return updateQuery() }
@@ -216,11 +218,13 @@ func insertQuery() string {
name,
config_file,
value,
-secure) VALUES (
+secure,
+comment) VALUES (
:name,
:config_file,
:value,
-:secure) RETURNING id,last_updated`
+:secure,
+:comment) RETURNING id,last_updated`
return query
}
@@ -233,6 +237,7 @@ p.last_updated,
p.name,
p.value,
p.secure,
+p.comment,
COALESCE(array_to_json(array_agg(pr.name) FILTER (WHERE pr.name IS NOT NULL)), '[]') AS profiles
FROM parameter p
LEFT JOIN profile_parameter pp ON p.id = pp.parameter
@@ -247,14 +252,15 @@ config_file=:config_file,
id=:id,
name=:name,
value=:value,
-secure=:secure
+secure=:secure,
+comment=:comment
WHERE id=:id RETURNING last_updated`
return query
}
// ParametersGroupBy ...
func ParametersGroupBy() string {
- groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure`
+ groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name, p.value, p.secure, p.comment`
return groupBy
}
@@ -282,6 +288,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) {
NameQueryParam: {Column: "p.name"},
SecureQueryParam: {Column: "p.secure", Checker: api.IsBool},
ValueQueryParam: {Column: "p.value"},
+ CommentQueryParam: {Column: "p.comment"},
}
if _, ok := inf.Params["orderby"]; !ok {
inf.Params["orderby"] = "name"
@@ -316,7 +323,7 @@ func GetParameters(w http.ResponseWriter, r *http.Request) {
params := tc.ParameterNullableV5{}
paramsList := []tc.ParameterNullableV5{}
for rows.Next() {
- if err = rows.Scan(¶ms.ConfigFile, ¶ms.ID, ¶ms.LastUpdated, ¶ms.Name, ¶ms.Value, ¶ms.Secure, ¶ms.Profiles); err != nil {
+ if err = rows.Scan(¶ms.ConfigFile, ¶ms.ID, ¶ms.LastUpdated, ¶ms.Name, ¶ms.Value, ¶ms.Secure, ¶ms.Comment, ¶ms.Profiles); err != nil {
api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting parameter(s): %w", err))
return
}
@@ -389,10 +396,11 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) {
name,
config_file,
value,
- secure
+ secure,
+ comment
) VALUES (
- $1, $2, $3, $4
- ) RETURNING id, name, config_file, value, last_updated, secure
+ $1, $2, $3, $4, $5
+ ) RETURNING id, name, config_file, value, last_updated, secure, comment
`
err = tx.QueryRow(
query,
@@ -400,6 +408,7 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) {
parameter.ConfigFile,
parameter.Value,
parameter.Secure,
+ parameter.Comment,
).Scan(
&objParam.ID,
@@ -408,6 +417,7 @@ func CreateParameter(w http.ResponseWriter, r *http.Request) {
&objParam.Value,
&objParam.LastUpdated,
&objParam.Secure,
+ &objParam.Comment,
)
if err != nil {
@@ -463,9 +473,10 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) {
config_file = $1,
name = $2,
value = $3,
- secure = $4
+ secure = $4,
+ comment = $5
WHERE
- p.id = $5
+ p.id = $6
RETURNING
p.id,
p.last_updated
@@ -477,6 +488,7 @@ func UpdateParameter(w http.ResponseWriter, r *http.Request) {
parameter.Name,
parameter.Value,
parameter.Secure,
+ parameter.Comment,
requestedID,
).Scan(
¶meter.ID,
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
index f806ffdb52..97213df84a 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters_test.go
@@ -42,6 +42,7 @@ func getTestParameters() []tc.ParameterNullable {
ID := 1
param := "paramname1"
val := "val1"
+ cmt := "cmt"
testParameter := tc.ParameterNullable{
ConfigFile: &configFile,
@@ -51,6 +52,7 @@ func getTestParameters() []tc.ParameterNullable {
Profiles: json.RawMessage(`["foo","bar"]`),
Secure: &secureFlag,
Value: &val,
+ Comment: &cmt,
}
parameters = append(parameters, testParameter)
@@ -59,6 +61,7 @@ func getTestParameters() []tc.ParameterNullable {
testParameter2.Value = &val
testParameter2.ConfigFile = &configFile
testParameter2.Profiles = json.RawMessage(`["foo","baz"]`)
+ testParameter2.Comment = &cmt
parameters = append(parameters, testParameter2)
return parameters
@@ -88,6 +91,7 @@ func TestGetParameters(t *testing.T) {
ts.Profiles,
ts.Secure,
ts.Value,
+ ts.Comment,
)
}
mock.ExpectBegin()
diff --git a/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go b/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go
index 658540284e..57e168b3ce 100644
--- a/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go
+++ b/traffic_ops/traffic_ops_golang/systeminfo/system_info_test.go
@@ -53,10 +53,12 @@ func TestGetSystemInfo(t *testing.T) {
firstID := 1
firstName := "paramname1"
firstVal := "val1"
+ firstCmt := "cmt1"
secondID := 2
secondName := "paramname2"
secondVal := "val2"
+ secondCmt := "cmt2"
var sysInfoParameters = []tc.ParameterNullable{
tc.ParameterNullable{
@@ -67,6 +69,7 @@ func TestGetSystemInfo(t *testing.T) {
Profiles: json.RawMessage(`["foo","bar"]`),
Secure: &secure,
Value: &firstVal,
+ Comment: &firstCmt,
},
tc.ParameterNullable{
@@ -77,6 +80,7 @@ func TestGetSystemInfo(t *testing.T) {
Profiles: json.RawMessage(`["foo","bar"]`),
Secure: &secure,
Value: &secondVal,
+ Comment: &secondCmt,
},
}
@@ -89,6 +93,7 @@ func TestGetSystemInfo(t *testing.T) {
ts.Profiles,
ts.Secure,
ts.Value,
+ ts.Comment,
)
}
diff --git a/traffic_portal/.gitignore b/traffic_portal/.gitignore
index b856303de5..d598874725 100644
--- a/traffic_portal/.gitignore
+++ b/traffic_portal/.gitignore
@@ -18,6 +18,7 @@
.tmp
.sass-cache
server/log/access.log
+pnpm-lock.yaml
node_modules
app/dist
Gemfile.lock
diff --git a/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html b/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html
index ac0db2b976..a00ef59f07 100644
--- a/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html
+++ b/traffic_portal/app/src/common/modules/form/parameter/form.parameter.tpl.html
@@ -66,6 +66,14 @@ under the License.
<small class="input-error" ng-show="hasPropertyError(parameterForm.secure, 'required')">Required</small>
</div>
</div>
+ <div class="form-group" ng-class="{'has-error': hasError(parameterForm.comment), 'has-feedback': hasError(parameterForm.comment)}">
+ <label class="control-label col-md-2 col-sm-2 col-xs-12">Comment</label>
+ <div class="col-md-10 col-sm-10 col-xs-12">
+ <textarea name="value" type="text" class="form-control" ng-model="parameter.comment" rows="10" autofocus></textarea>
+ <small class="input-error" ng-show="hasPropertyError(parameterForm.comment, 'required')">Required</small>
+ <span ng-show="hasError(parameterForm.comment)" class="form-control-feedback"><i class="fa fa-times"></i></span>
+ </div>
+ </div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" ng-show="!settings.isNew" ng-click="confirmDelete(parameter)">Delete</button>
<button type="button" class="btn btn-success" ng-disabled="parameterForm.$pristine || parameterForm.$invalid" ng-click="confirmSave(parameter)">{{settings.saveLabel}}</button>
diff --git a/traffic_portal/app/src/common/modules/table/parameters/TableParametersController.js b/traffic_portal/app/src/common/modules/table/parameters/TableParametersController.js
index 88c0bba0dd..233d34cf79 100644
--- a/traffic_portal/app/src/common/modules/table/parameters/TableParametersController.js
+++ b/traffic_portal/app/src/common/modules/table/parameters/TableParametersController.js
@@ -27,8 +27,9 @@
* @param {import("../../../api/ParameterService")} parameterService
* @param {import("../../../api/ProfileService")} profileService
* @param {import("../../../models/MessageModel")} messageModel
+ * @param {import("../../../models/PropertiesModel")} propertiesModel
*/
-var TableParametersController = function(parameters, $scope, $state, $uibModal, $window, locationUtils, parameterService, profileService, messageModel) {
+var TableParametersController = function(parameters, $scope, $state, $uibModal, $window, locationUtils, parameterService, profileService, messageModel, propertiesModel) {
let parametersTable;
@@ -96,7 +97,8 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
{ "name": "Config File", "visible": true, "searchable": true },
{ "name": "Value", "visible": true, "searchable": true },
{ "name": "Secure", "visible": true, "searchable": true },
- { "name": "Profiles", "visible": true, "searchable": true }
+ { "name": "Profiles", "visible": true, "searchable": true },
+ { "name": "Comment", "visible": true, "searchable": true }
];
$scope.contextMenuItems = [
@@ -153,6 +155,13 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
return true;
};
+ $scope.show = function (colName) {
+ if (colName === "Comment") {
+ return propertiesModel.properties.parameters.comment.show;
+ }
+ return true;
+ }
+
angular.element(document).ready(function () {
parametersTable = $('#parametersTable').DataTable({
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
@@ -175,5 +184,5 @@ var TableParametersController = function(parameters, $scope, $state, $uibModal,
};
-TableParametersController.$inject = ['parameters', '$scope', '$state', '$uibModal', '$window', 'locationUtils', 'parameterService', 'profileService', 'messageModel'];
+TableParametersController.$inject = ['parameters', '$scope', '$state', '$uibModal', '$window', 'locationUtils', 'parameterService', 'profileService', 'messageModel', 'propertiesModel'];
module.exports = TableParametersController;
diff --git a/traffic_portal/app/src/common/modules/table/parameters/table.parameters.tpl.html b/traffic_portal/app/src/common/modules/table/parameters/table.parameters.tpl.html
index 6bb2e7e8a3..99000922f5 100644
--- a/traffic_portal/app/src/common/modules/table/parameters/table.parameters.tpl.html
+++ b/traffic_portal/app/src/common/modules/table/parameters/table.parameters.tpl.html
@@ -31,7 +31,7 @@ under the License.
<span class="caret"></span>
</button>
<menu ng-click="$event.stopPropagation()" class="column-settings dropdown-menu-right dropdown-menu" uib-dropdown-menu>
- <li role="menuitem" ng-repeat="c in columns | orderBy:'name'">
+ <li ng-show="show(c.name)" role="menuitem" ng-repeat="c in columns | orderBy:'name'">
<div class="checkbox">
<label><input type="checkbox" ng-model="c.visible" ng-click="toggleVisibility(c.name)"> {{::c.name}}</label>
</div>
@@ -51,6 +51,7 @@ under the License.
<th>Value</th>
<th>Secure</th>
<th>Profiles</th>
+ <th ng-show="show('Comment')">Comment</th>
</tr>
</thead>
<tbody>
@@ -60,6 +61,7 @@ under the License.
<td data-search="^{{::p.value}}$">{{::p.value}}</td>
<td data-search="^{{::p.secure}}$">{{::p.secure}}</td>
<td data-search="{{::p.profiles}}" uib-popover="{{::p.profiles.sort().join(',\n')}}" popover-title="Profiles" popover-trigger="mouseenter" popover-placement="left" popover-append-to-body="true">{{p.profiles.length}}</td>
+ <td ng-show="show('Comment')" data-search="^{{::p.comment}}$">{{::p.comment}}</td>
</tr>
</tbody>
</table>
diff --git a/traffic_portal/app/src/traffic_portal_properties.json b/traffic_portal/app/src/traffic_portal_properties.json
index 8dd1e71388..ec214001ef 100644
--- a/traffic_portal/app/src/traffic_portal_properties.json
+++ b/traffic_portal/app/src/traffic_portal_properties.json
@@ -206,6 +206,13 @@
"baseUrl": "https://trafficstats.domain.com/dashboard/script/traffic_ops_server.js?which="
}
},
+ "parameters": {
+ "_comment": "Parameter settings",
+ "comment": {
+ "_comment": "Show/hide comment field",
+ "show": false
+ }
+ },
"changeLogs": {
"_comment": "Change log settings",
"days": 7