You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2021/06/29 17:58:58 UTC

[GitHub] [brooklyn-ui] algairim opened a new pull request #235: Convert logbook into directive

algairim opened a new pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235


   Signed-off-by: Mykola Mandra <my...@cloudsoftcorp.com>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] jcabrerizo commented on pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
jcabrerizo commented on pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#issuecomment-874165236


   LGTM @algairim Thanks for tidying this up!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662790656



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));
+
+        $scope.$on('logbook.query', () => {
+            vm.doQuery();
+        });
+
+        vm.getChecked = function (group) {
+            let levels = [];
+            group.forEach(function (item) {
+                if (item.selected) levels.push(item.value);
+            });
+            return levels;
+        }
+        vm.doQuery = function () {
+            $scope.waitingResponse = true;
+            $scope.results = "Loading..."
+
+            const levels = $scope.allLevels ? ['ALL'] : vm.getChecked($scope.logLevels);
+
+            const params = {
+                reverseOrder: $scope.reverseOrder,
+                numberOfItems: $scope.numberOfItems,
+                levels: levels,
+                initTime: $scope.initTime,
+                finalTime: $scope.finalTime,
+            }
+
+            logbookApi.logbookQuery(params, true).then(function (success) {
+                // TODO implement logic for make output as table
+                $scope.logEntries = success;
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+                scrollToMostRecentRecords();
+            }, function (error) {
+                $scope.results = "Error getting the logs: \n" + error.error.message;
+                console.log(JSON.stringify(error));
+            }).finally(() => {
+                $scope.waitingResponse = false;
+            });
+        };
+
+        vm.createLogOutputAsText = function (success) {
+            let output = [];
+            const fieldsToShow = vm.getChecked($scope.logFields);
+            success.forEach(entry => {
+                let outputLine = [];
+                if (fieldsToShow.includes("datetime") && entry.timestamp)
+                    outputLine.push(entry.timestamp);
+                if (fieldsToShow.includes("taskId") && entry.taskId)
+                    outputLine.push(entry.taskId);
+                if (fieldsToShow.includes("entityIds") && entry.entityIds)
+                    outputLine.push(entry.entityIds);
+                if (fieldsToShow.includes("level") && entry.level)
+                    outputLine.push(entry.level);
+                if (fieldsToShow.includes("bundleId") && entry.bundleId)
+                    outputLine.push(entry.bundleId);
+                if (fieldsToShow.includes("class") && entry.class)
+                    outputLine.push(entry.class);
+                if (fieldsToShow.includes("threadName") && entry.threadName)
+                    outputLine.push(entry.threadName);
+                if (fieldsToShow.includes("message") && entry.message)
+                    outputLine.push(entry.message);
+
+                output.push(outputLine.join(" "));
+            })
+            return output.length > 0 ? output.join("\n") : "No results";
+        }
+
+        vm.resetForm = function () {
+            $scope.numberOfItems = 1000;
+            $scope.allLevels = true
+            $scope.logLevels = [
+                {"name": "Debug", "value": "DEBUG", "selected": false},
+                {"name": "Info", "value": "INFO ", "selected": false},
+                {"name": "Warn", "value": "WARN ", "selected": false},
+                {"name": "Error", "value": "ERROR", "selected": false},
+                {"name": "Fatal", "value": "FATAL", "selected": false},
+            ];
+            $scope.fieldsToShow = ['datetime', 'class', 'message']
+            $scope.logFields = [
+                {"name": "Timestamp", "value": "datetime", "selected": true},
+                {"name": "Task ID", "value": "taskId", "selected": false},
+                {"name": "Entity IDs", "value": "entityIds", "selected": false},
+                {"name": "Log level", "value": "level", "selected": true},
+                {"name": "Bundle ID", "value": "bundleId", "selected": false},
+                {"name": "Class", "value": "class", "selected": true},
+                {"name": "Thread name", "value": "threadName", "selected": false},
+                {"name": "Message", "value": "message", "selected": true},
+            ];
+            $scope.reverseOrder = false;
+            $scope.initTime = "";
+            $scope.finalTime = "";
+        }
+
+        $scope.$watch('allLevels', function (v) {
+            if (!v) {
+                if (vm.getChecked($scope.logLevels).length === 0) {
+                    $scope.allLevels = true;
+                } else {
+                    return;
+                }
+            }
+            for (let i = 0; i < $scope.logLevels.length; ++i) {
+                $scope.logLevels[i].selected = false;
+            }
+        });
+
+        $scope.$watch('logLevels', function (newVal, oldVal) {
+            let selected = newVal.reduce(function (s, c) {
+                return s + (c.selected ? 1 : 0);
+            }, 0);
+            if (selected === newVal.length || selected === 0) {
+                $scope.allLevels = true;
+            } else if (selected > 0) {
+                $scope.allLevels = false;
+            }
+        }, true);
+
+        $scope.$watch('logFields', function (newVal, oldVal) {
+            if ($scope.logEntries !== "") {
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+            }
+        }, true);
+
+        /**
+         * Scrolls down to the most recent records if order is not set to reverse.
+         */
+        function scrollToMostRecentRecords() {
+            $scope.$applyAsync(() => {
+                if ($scope.reverseOrder) {
+                    // NOOP: no need to scroll down. Reverse order displays the most recent records at the beginning.
+                } else {
+                    // Scroll down to the most recent records.
+                    scrollableElements.forEach(item => item.scrollTop = item.scrollHeight);
+                }
+            });
+        }

Review comment:
       Added auto-scroll, depending on reverse order, to address requirement to display last 1000 lines.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662792131



##########
File path: ui-modules/utils/logbook/logbook.template.html
##########
@@ -0,0 +1,60 @@
+<!--

Review comment:
       This file was moved with a couple of changes, see comments below.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662791383



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));
+
+        $scope.$on('logbook.query', () => {
+            vm.doQuery();
+        });
+
+        vm.getChecked = function (group) {
+            let levels = [];
+            group.forEach(function (item) {
+                if (item.selected) levels.push(item.value);
+            });
+            return levels;
+        }
+        vm.doQuery = function () {
+            $scope.waitingResponse = true;
+            $scope.results = "Loading..."
+
+            const levels = $scope.allLevels ? ['ALL'] : vm.getChecked($scope.logLevels);
+
+            const params = {
+                reverseOrder: $scope.reverseOrder,
+                numberOfItems: $scope.numberOfItems,
+                levels: levels,
+                initTime: $scope.initTime,
+                finalTime: $scope.finalTime,
+            }
+
+            logbookApi.logbookQuery(params, true).then(function (success) {
+                // TODO implement logic for make output as table
+                $scope.logEntries = success;
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+                scrollToMostRecentRecords();
+            }, function (error) {
+                $scope.results = "Error getting the logs: \n" + error.error.message;
+                console.log(JSON.stringify(error));
+            }).finally(() => {
+                $scope.waitingResponse = false;
+            });
+        };
+
+        vm.createLogOutputAsText = function (success) {
+            let output = [];
+            const fieldsToShow = vm.getChecked($scope.logFields);
+            success.forEach(entry => {
+                let outputLine = [];
+                if (fieldsToShow.includes("datetime") && entry.timestamp)
+                    outputLine.push(entry.timestamp);
+                if (fieldsToShow.includes("taskId") && entry.taskId)
+                    outputLine.push(entry.taskId);
+                if (fieldsToShow.includes("entityIds") && entry.entityIds)
+                    outputLine.push(entry.entityIds);
+                if (fieldsToShow.includes("level") && entry.level)
+                    outputLine.push(entry.level);
+                if (fieldsToShow.includes("bundleId") && entry.bundleId)
+                    outputLine.push(entry.bundleId);
+                if (fieldsToShow.includes("class") && entry.class)
+                    outputLine.push(entry.class);
+                if (fieldsToShow.includes("threadName") && entry.threadName)
+                    outputLine.push(entry.threadName);
+                if (fieldsToShow.includes("message") && entry.message)
+                    outputLine.push(entry.message);
+
+                output.push(outputLine.join(" "));
+            })
+            return output.length > 0 ? output.join("\n") : "No results";
+        }
+
+        vm.resetForm = function () {
+            $scope.numberOfItems = 1000;

Review comment:
       Default number of items suggested in the query is 1000 now, instead of 10 previously.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662792736



##########
File path: ui-modules/utils/logbook/logbook.template.html
##########
@@ -0,0 +1,60 @@
+<!--
+  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.
+-->
+

Review comment:
       Removed <div> that wrapped the whole logbook section. No need for that in a separate template, keep it flexible for anything to re-use.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662790656



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));
+
+        $scope.$on('logbook.query', () => {
+            vm.doQuery();
+        });
+
+        vm.getChecked = function (group) {
+            let levels = [];
+            group.forEach(function (item) {
+                if (item.selected) levels.push(item.value);
+            });
+            return levels;
+        }
+        vm.doQuery = function () {
+            $scope.waitingResponse = true;
+            $scope.results = "Loading..."
+
+            const levels = $scope.allLevels ? ['ALL'] : vm.getChecked($scope.logLevels);
+
+            const params = {
+                reverseOrder: $scope.reverseOrder,
+                numberOfItems: $scope.numberOfItems,
+                levels: levels,
+                initTime: $scope.initTime,
+                finalTime: $scope.finalTime,
+            }
+
+            logbookApi.logbookQuery(params, true).then(function (success) {
+                // TODO implement logic for make output as table
+                $scope.logEntries = success;
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+                scrollToMostRecentRecords();
+            }, function (error) {
+                $scope.results = "Error getting the logs: \n" + error.error.message;
+                console.log(JSON.stringify(error));
+            }).finally(() => {
+                $scope.waitingResponse = false;
+            });
+        };
+
+        vm.createLogOutputAsText = function (success) {
+            let output = [];
+            const fieldsToShow = vm.getChecked($scope.logFields);
+            success.forEach(entry => {
+                let outputLine = [];
+                if (fieldsToShow.includes("datetime") && entry.timestamp)
+                    outputLine.push(entry.timestamp);
+                if (fieldsToShow.includes("taskId") && entry.taskId)
+                    outputLine.push(entry.taskId);
+                if (fieldsToShow.includes("entityIds") && entry.entityIds)
+                    outputLine.push(entry.entityIds);
+                if (fieldsToShow.includes("level") && entry.level)
+                    outputLine.push(entry.level);
+                if (fieldsToShow.includes("bundleId") && entry.bundleId)
+                    outputLine.push(entry.bundleId);
+                if (fieldsToShow.includes("class") && entry.class)
+                    outputLine.push(entry.class);
+                if (fieldsToShow.includes("threadName") && entry.threadName)
+                    outputLine.push(entry.threadName);
+                if (fieldsToShow.includes("message") && entry.message)
+                    outputLine.push(entry.message);
+
+                output.push(outputLine.join(" "));
+            })
+            return output.length > 0 ? output.join("\n") : "No results";
+        }
+
+        vm.resetForm = function () {
+            $scope.numberOfItems = 1000;
+            $scope.allLevels = true
+            $scope.logLevels = [
+                {"name": "Debug", "value": "DEBUG", "selected": false},
+                {"name": "Info", "value": "INFO ", "selected": false},
+                {"name": "Warn", "value": "WARN ", "selected": false},
+                {"name": "Error", "value": "ERROR", "selected": false},
+                {"name": "Fatal", "value": "FATAL", "selected": false},
+            ];
+            $scope.fieldsToShow = ['datetime', 'class', 'message']
+            $scope.logFields = [
+                {"name": "Timestamp", "value": "datetime", "selected": true},
+                {"name": "Task ID", "value": "taskId", "selected": false},
+                {"name": "Entity IDs", "value": "entityIds", "selected": false},
+                {"name": "Log level", "value": "level", "selected": true},
+                {"name": "Bundle ID", "value": "bundleId", "selected": false},
+                {"name": "Class", "value": "class", "selected": true},
+                {"name": "Thread name", "value": "threadName", "selected": false},
+                {"name": "Message", "value": "message", "selected": true},
+            ];
+            $scope.reverseOrder = false;
+            $scope.initTime = "";
+            $scope.finalTime = "";
+        }
+
+        $scope.$watch('allLevels', function (v) {
+            if (!v) {
+                if (vm.getChecked($scope.logLevels).length === 0) {
+                    $scope.allLevels = true;
+                } else {
+                    return;
+                }
+            }
+            for (let i = 0; i < $scope.logLevels.length; ++i) {
+                $scope.logLevels[i].selected = false;
+            }
+        });
+
+        $scope.$watch('logLevels', function (newVal, oldVal) {
+            let selected = newVal.reduce(function (s, c) {
+                return s + (c.selected ? 1 : 0);
+            }, 0);
+            if (selected === newVal.length || selected === 0) {
+                $scope.allLevels = true;
+            } else if (selected > 0) {
+                $scope.allLevels = false;
+            }
+        }, true);
+
+        $scope.$watch('logFields', function (newVal, oldVal) {
+            if ($scope.logEntries !== "") {
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+            }
+        }, true);
+
+        /**
+         * Scrolls down to the most recent records if order is not set to reverse.
+         */
+        function scrollToMostRecentRecords() {
+            $scope.$applyAsync(() => {
+                if ($scope.reverseOrder) {
+                    // NOOP: no need to scroll down. Reverse order displays the most recent records at the beginning.
+                } else {
+                    // Scroll down to the most recent records.
+                    scrollableElements.forEach(item => item.scrollTop = item.scrollHeight);
+                }
+            });
+        }

Review comment:
       Added scroll to address requirement to display last 1000 lines.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662794183



##########
File path: ui-modules/home/app/views/about/about.template.html
##########
@@ -77,8 +77,6 @@ <h2>HA status</h2>
                 </tr>
                 </tbody>
             </table>
-            <h2>Logbook</h2>
-            <a class="btn btn-sm btn-default" href="#!/logbook"><i class="fa fa-eye"></i> Logbook</a>

Review comment:
       Open to suggestions on how to hide/display the logbook, e.g. return back the button, accordion, etc.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662796451



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));

Review comment:
       Scrollable elements to support auto-scroll logic.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662793818



##########
File path: ui-modules/home/app/views/about/about.template.html
##########
@@ -77,8 +77,6 @@ <h2>HA status</h2>
                 </tr>
                 </tbody>
             </table>
-            <h2>Logbook</h2>
-            <a class="btn btn-sm btn-default" href="#!/logbook"><i class="fa fa-eye"></i> Logbook</a>

Review comment:
       Logbook was moved down as a directive, not as a state. Button looks like not required.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] jcabrerizo commented on pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
jcabrerizo commented on pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#issuecomment-874165236


   LGTM @algairim Thanks for tidying this up!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662792736



##########
File path: ui-modules/utils/logbook/logbook.template.html
##########
@@ -0,0 +1,60 @@
+<!--
+  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.
+-->
+

Review comment:
       Removed styled `<div>` that wrapped the whole logbook section. No need for that in a separate template, keep it flexible for anything to re-use.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662794461



##########
File path: ui-modules/home/app/views/about/about.template.html
##########
@@ -93,4 +91,7 @@ <h4 class="list-group-item-heading">{{feature.name}}</h4>
             </ul>
         </div>
     </div>
+
+    <h2>Logbook</h2>
+    <br-logbook></br-logbook>

Review comment:
       Open to suggestions on how to hide/display the logbook if needed, e.g. return back the button, accordion, etc.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662796052



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));
+
+        $scope.$on('logbook.query', () => {
+            vm.doQuery();
+        });
+
+        vm.getChecked = function (group) {
+            let levels = [];
+            group.forEach(function (item) {
+                if (item.selected) levels.push(item.value);
+            });
+            return levels;
+        }
+        vm.doQuery = function () {
+            $scope.waitingResponse = true;
+            $scope.results = "Loading..."
+
+            const levels = $scope.allLevels ? ['ALL'] : vm.getChecked($scope.logLevels);
+
+            const params = {
+                reverseOrder: $scope.reverseOrder,
+                numberOfItems: $scope.numberOfItems,
+                levels: levels,
+                initTime: $scope.initTime,
+                finalTime: $scope.finalTime,
+            }
+
+            logbookApi.logbookQuery(params, true).then(function (success) {
+                // TODO implement logic for make output as table
+                $scope.logEntries = success;
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+                scrollToMostRecentRecords();

Review comment:
       Auto-scroll is called once log entries are displayed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] jcabrerizo merged pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
jcabrerizo merged pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662790334



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*

Review comment:
       This file was moved.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662790334



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*

Review comment:
       This file was moved with a couple of changes, see comments below.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] jcabrerizo merged pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
jcabrerizo merged pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on a change in pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on a change in pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#discussion_r662790656



##########
File path: ui-modules/utils/logbook/logbook.js
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+import angular from 'angular';
+import template from './logbook.template.html';
+import {HIDE_INTERSTITIAL_SPINNER_EVENT} from '../interstitial-spinner/interstitial-spinner';
+
+const MODULE_NAME = 'brooklyn.component.logbook';
+
+angular.module(MODULE_NAME, [])
+    .directive('brLogbook', logbook);
+
+export default MODULE_NAME;
+
+export function logbook() {
+
+    return {
+        template: template,
+        controller: ['$scope', '$element', 'brBrandInfo', 'logbookApi', controller],
+        controllerAs: 'vm'
+    };
+
+    function controller($scope, $element, brBrandInfo, logbookApi) {
+        $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
+        $scope.getBrandedText = brBrandInfo.getBrandedText;
+
+        let vm = this;
+        let scrollableElements = Array.from($element.find('textarea'));
+
+        $scope.$on('logbook.query', () => {
+            vm.doQuery();
+        });
+
+        vm.getChecked = function (group) {
+            let levels = [];
+            group.forEach(function (item) {
+                if (item.selected) levels.push(item.value);
+            });
+            return levels;
+        }
+        vm.doQuery = function () {
+            $scope.waitingResponse = true;
+            $scope.results = "Loading..."
+
+            const levels = $scope.allLevels ? ['ALL'] : vm.getChecked($scope.logLevels);
+
+            const params = {
+                reverseOrder: $scope.reverseOrder,
+                numberOfItems: $scope.numberOfItems,
+                levels: levels,
+                initTime: $scope.initTime,
+                finalTime: $scope.finalTime,
+            }
+
+            logbookApi.logbookQuery(params, true).then(function (success) {
+                // TODO implement logic for make output as table
+                $scope.logEntries = success;
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+                scrollToMostRecentRecords();
+            }, function (error) {
+                $scope.results = "Error getting the logs: \n" + error.error.message;
+                console.log(JSON.stringify(error));
+            }).finally(() => {
+                $scope.waitingResponse = false;
+            });
+        };
+
+        vm.createLogOutputAsText = function (success) {
+            let output = [];
+            const fieldsToShow = vm.getChecked($scope.logFields);
+            success.forEach(entry => {
+                let outputLine = [];
+                if (fieldsToShow.includes("datetime") && entry.timestamp)
+                    outputLine.push(entry.timestamp);
+                if (fieldsToShow.includes("taskId") && entry.taskId)
+                    outputLine.push(entry.taskId);
+                if (fieldsToShow.includes("entityIds") && entry.entityIds)
+                    outputLine.push(entry.entityIds);
+                if (fieldsToShow.includes("level") && entry.level)
+                    outputLine.push(entry.level);
+                if (fieldsToShow.includes("bundleId") && entry.bundleId)
+                    outputLine.push(entry.bundleId);
+                if (fieldsToShow.includes("class") && entry.class)
+                    outputLine.push(entry.class);
+                if (fieldsToShow.includes("threadName") && entry.threadName)
+                    outputLine.push(entry.threadName);
+                if (fieldsToShow.includes("message") && entry.message)
+                    outputLine.push(entry.message);
+
+                output.push(outputLine.join(" "));
+            })
+            return output.length > 0 ? output.join("\n") : "No results";
+        }
+
+        vm.resetForm = function () {
+            $scope.numberOfItems = 1000;
+            $scope.allLevels = true
+            $scope.logLevels = [
+                {"name": "Debug", "value": "DEBUG", "selected": false},
+                {"name": "Info", "value": "INFO ", "selected": false},
+                {"name": "Warn", "value": "WARN ", "selected": false},
+                {"name": "Error", "value": "ERROR", "selected": false},
+                {"name": "Fatal", "value": "FATAL", "selected": false},
+            ];
+            $scope.fieldsToShow = ['datetime', 'class', 'message']
+            $scope.logFields = [
+                {"name": "Timestamp", "value": "datetime", "selected": true},
+                {"name": "Task ID", "value": "taskId", "selected": false},
+                {"name": "Entity IDs", "value": "entityIds", "selected": false},
+                {"name": "Log level", "value": "level", "selected": true},
+                {"name": "Bundle ID", "value": "bundleId", "selected": false},
+                {"name": "Class", "value": "class", "selected": true},
+                {"name": "Thread name", "value": "threadName", "selected": false},
+                {"name": "Message", "value": "message", "selected": true},
+            ];
+            $scope.reverseOrder = false;
+            $scope.initTime = "";
+            $scope.finalTime = "";
+        }
+
+        $scope.$watch('allLevels', function (v) {
+            if (!v) {
+                if (vm.getChecked($scope.logLevels).length === 0) {
+                    $scope.allLevels = true;
+                } else {
+                    return;
+                }
+            }
+            for (let i = 0; i < $scope.logLevels.length; ++i) {
+                $scope.logLevels[i].selected = false;
+            }
+        });
+
+        $scope.$watch('logLevels', function (newVal, oldVal) {
+            let selected = newVal.reduce(function (s, c) {
+                return s + (c.selected ? 1 : 0);
+            }, 0);
+            if (selected === newVal.length || selected === 0) {
+                $scope.allLevels = true;
+            } else if (selected > 0) {
+                $scope.allLevels = false;
+            }
+        }, true);
+
+        $scope.$watch('logFields', function (newVal, oldVal) {
+            if ($scope.logEntries !== "") {
+                $scope.results = vm.createLogOutputAsText($scope.logEntries);
+            }
+        }, true);
+
+        /**
+         * Scrolls down to the most recent records if order is not set to reverse.
+         */
+        function scrollToMostRecentRecords() {
+            $scope.$applyAsync(() => {
+                if ($scope.reverseOrder) {
+                    // NOOP: no need to scroll down. Reverse order displays the most recent records at the beginning.
+                } else {
+                    // Scroll down to the most recent records.
+                    scrollableElements.forEach(item => item.scrollTop = item.scrollHeight);
+                }
+            });
+        }

Review comment:
       Added auto-scroll that depends on reverse order, to address requirement to display last 1000 lines.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [brooklyn-ui] algairim commented on pull request #235: Refactoring: convert logbook into directive

Posted by GitBox <gi...@apache.org>.
algairim commented on pull request #235:
URL: https://github.com/apache/brooklyn-ui/pull/235#issuecomment-870804278


   <img width="962" alt="Screenshot 2021-06-29 at 19 03 00" src="https://user-images.githubusercontent.com/81319331/123845898-a241fa80-d90c-11eb-84a7-4e3d3fdf951c.png">
   
   Removed button. Logbook is now a directive.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org