client-app/app/components/env-tab.js in logster-2.1.1 vs client-app/app/components/env-tab.js in logster-2.1.2
- old
+ new
@@ -1,44 +1,80 @@
-import Component from "@ember/component";
-import { computed } from "@ember/object";
-import { buildHashString } from "client-app/lib/utilities";
-
-export default Component.extend({
- current: 1,
-
- didUpdateAttrs() {
- this.set("current", 1);
- },
-
- isEnvArray: computed("message.env", function() {
- return Array.isArray(this.get("message.env"));
- }),
-
- html: computed("isEnvArray", "current", function() {
- if (!this.get("isEnvArray")) {
- return buildHashString(this.get("message.env"));
- } else {
- const currentEnv = this.get("message.env")[this.get("current") - 1];
- return buildHashString(currentEnv);
- }
- }),
-
- disableBackButtons: computed("current", function() {
- return this.get("current") === 1;
- }),
-
- disableForwardButtons: computed("current", "message.env.length", function() {
- return this.get("current") === this.get("message.env.length");
- }),
-
- actions: {
- takeStep(dir) {
- const amount = dir === "back" ? -1 : 1;
- this.set("current", this.get("current") + amount);
- },
-
- bigJump(dir) {
- const newCurrent = dir === "back" ? 1 : this.get("message.env.length");
- this.set("current", newCurrent);
- }
- }
-});
+import Component from "@ember/component";
+import { computed } from "@ember/object";
+import { buildHashString } from "client-app/lib/utilities";
+import Preload from "client-app/lib/preload";
+
+export default Component.extend({
+ current: 1,
+
+ didUpdateAttrs() {
+ this.setProperties({
+ current: 1,
+ expanded: null
+ });
+ },
+
+ isEnvArray: computed("message.env", function() {
+ return Array.isArray(this.get("message.env"));
+ }),
+
+ html: computed("isEnvArray", "current", "expanded.[]", function() {
+ if (!this.get("isEnvArray")) {
+ return buildHashString(this.get("message.env"));
+ } else {
+ const currentEnv = Em.$.extend(
+ {},
+ this.get("message.env")[this.get("current") - 1]
+ );
+ const expandableKeys = Preload.get("env_expandable_keys") || [];
+ expandableKeys.forEach(key => {
+ if (currentEnv.hasOwnProperty(key) && !Array.isArray(currentEnv[key])) {
+ const list = [currentEnv[key]];
+ this.get("message.env").forEach(env => {
+ if (env[key] && list.indexOf(env[key]) === -1) {
+ list.push(env[key]);
+ }
+ });
+ currentEnv[key] = list.length > 1 ? list : list[0];
+ }
+ });
+ return buildHashString(currentEnv, false, this.get("expanded") || []);
+ }
+ }),
+
+ click(e) {
+ const $elem = Em.$(e.target);
+ const dataKey = $elem.attr("data-key");
+ const expandableKeys = Preload.get("env_expandable_keys") || [];
+ if (
+ expandableKeys.indexOf(dataKey) !== -1 &&
+ $elem.hasClass("expand-list")
+ ) {
+ e.preventDefault();
+ if (!this.get("expanded")) {
+ this.set("expanded", [dataKey]);
+ } else {
+ this.get("expanded").pushObject(dataKey);
+ }
+ }
+ },
+
+ disableBackButtons: computed("current", function() {
+ return this.get("current") === 1;
+ }),
+
+ disableForwardButtons: computed("current", "message.env.length", function() {
+ return this.get("current") === this.get("message.env.length");
+ }),
+
+ actions: {
+ takeStep(dir) {
+ const amount = dir === "back" ? -1 : 1;
+ this.set("current", this.get("current") + amount);
+ },
+
+ bigJump(dir) {
+ const newCurrent = dir === "back" ? 1 : this.get("message.env.length");
+ this.set("current", newCurrent);
+ }
+ }
+});