Status.vue 7.02 KB
Newer Older
WuFeiyang's avatar
WuFeiyang committed
1
<template>
WuFeiyang's avatar
WuFeiyang committed
2 3 4
  <b-container class="bv-example-row">
    <b-row style="margin-top:10px">
      <b-col>
5
        <span style="float:left;" class="smallFont">path: {{ config.data.url }}</span>
WuFeiyang's avatar
WuFeiyang committed
6 7
      </b-col>
      <b-col>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
        <b-button @click="showPathConfig" variant="primary" style="float:right">
          <span class="glyphicon glyphicon-cog"></span>
        </b-button>
      </b-col>
    </b-row>

    <br />

    <b-row>
      <b-col>
        <div
          style="width:100%;overflow:auto;border-style: solid; border-width: 1px;"
        >
          <p style="float:left;margin:0px" class="largeFont">{{ StatusValue }}</p>
        </div>
      </b-col>
    </b-row>

    <br />

    <b-row>
      <b-col>
        <b-input-group size="lg" prepend="path" v-show="isShowPath">
          <b-form-input v-model="config.data.url"></b-form-input>
          <b-input-group-append>
            <b-button @click="updateUI" text="Button" variant="primary">OK</b-button>
            <b-button variant="info" @click="pathPoke">poke</b-button>
          </b-input-group-append>
        </b-input-group>
      </b-col>
    </b-row>

    <b-row>
      <b-col>
        <WidgetParams
          ref="WidgetParams"
          v-show="isShowParams"
          action="get"
          @updataVariables="viewLoad"
        ></WidgetParams>
      </b-col>
    </b-row>

    <br />
    <b-row>
      <b-col>
        <Navigation ref="FamilyLink" :url="config.data.url"></Navigation>
WuFeiyang's avatar
WuFeiyang committed
55 56 57
      </b-col>
    </b-row>
  </b-container>
WuFeiyang's avatar
WuFeiyang committed
58 59 60 61
</template>

<script lang="ts">
import Vue from "vue";
62
import { VueSvgGauge } from "vue-svg-gauge";
WuFeiyang's avatar
WuFeiyang committed
63 64 65 66
import Component from "vue-class-component";
import { Prop, Watch } from "vue-property-decorator";
import { WidgetConfig } from "@/models/WidgetConfig";
import { UpdatePayload } from "@/models/UpdatePayload";
WuFeiyang's avatar
WuFeiyang committed
67
import { Widget } from "@/models/widget";
WuFeiyang's avatar
WuFeiyang committed
68
import { ResourceInfo } from "@/models/Customview";
WuFeiyang's avatar
WuFeiyang committed
69 70 71 72 73 74
import WidgetParams from "@/components/Common/WidgetParams.vue";
import axios from "axios";
import PathProcessor from "@/models/PathProcessor";
import StrMapObjChange from "@/models/StrMapObjChange";
import { forEach } from "typescript-collections/dist/lib/arrays";
import { map } from "d3";
75
import Navigation from "@/components/Common/Navigation.vue";
WuFeiyang's avatar
WuFeiyang committed
76 77 78

@Component({
  components: {
WuFeiyang's avatar
WuFeiyang committed
79
    WidgetParams,
WuFeiyang's avatar
WuFeiyang committed
80
    Navigation
WuFeiyang's avatar
WuFeiyang committed
81 82 83 84 85 86 87 88 89
  }
})
export default class Status extends Widget {
  pathProcessor = new PathProcessor();
  strMapObjChange = new StrMapObjChange();
  WidgetComponentName: string = "Status";
  StatusValue: string = "";
  pathId: string = "";
  userInputData = new Map<string, string>();
90 91
  pathwithVar: string = "";
  timer?: number;
WuFeiyang's avatar
WuFeiyang committed
92 93 94 95 96 97 98 99 100 101 102
  isShowPath: boolean = false;
  isShowParams: boolean = false;

  config: WidgetConfig = {
    WidgetComponentName: "Status",
    data: {
      url: "",
      userInputData: ""
    }
  };

WuFeiyang's avatar
WuFeiyang committed
103
  created() {
104 105 106
    this.config.data.userInputData = this.strMapObjChange.strMapToObj(
      this.userInputData
    );
WuFeiyang's avatar
WuFeiyang committed
107
  }
WuFeiyang's avatar
WuFeiyang committed
108

109 110
  mounted() {
    this.timer = setInterval(this.refresh, 1000);
111
  }
WuFeiyang's avatar
WuFeiyang committed
112

113
  destroyed() {
114 115
    clearInterval(this.timer);
  }
WuFeiyang's avatar
WuFeiyang committed
116

WuFeiyang's avatar
WuFeiyang committed
117
  updateUI() {
WuFeiyang's avatar
WuFeiyang committed
118
    this.isShowPath = false;
WuFeiyang's avatar
WuFeiyang committed
119
    this.isShowParams = true;
WuFeiyang's avatar
WuFeiyang committed
120 121 122 123 124 125 126 127 128 129 130 131 132
    var url = this.config.data.url;
    this.pathId = url.slice(0, url.indexOf("/"));
    (this.$refs.WidgetParams as WidgetParams).setVariableList(
      this.pathProcessor.extractVarFromPath(url)
    );
  }

  showPathConfig() {
    this.isShowPath = !this.isShowPath;
  }

  getConfig(): WidgetConfig {
    // this.config.data.userInputData =(this.$refs.WidgetParams as WidgetParams).getVariableValues();
133 134 135
    this.config.data.userInputData = this.strMapObjChange.strMapToObj(
      (this.$refs.WidgetParams as WidgetParams).getVariableValues()
    );
WuFeiyang's avatar
WuFeiyang committed
136 137 138 139 140 141 142 143
    return this.config;
  }

  setConfig(widgetConfig: WidgetConfig): void {
    this.config = widgetConfig;
    this.updateUI();
    //map不能序列化,必须要单独处理,这里的处理方法仅限map<string,string>类型
    var temp = this.config.data.userInputData;
WuFeiyang's avatar
WuFeiyang committed
144
    temp = JSON.parse(JSON.stringify(temp));
WuFeiyang's avatar
WuFeiyang committed
145 146
    temp = this.strMapObjChange.objToStrMap(temp);
    this.userInputData = temp;
147 148 149
    (this.$refs.WidgetParams as WidgetParams).setVariableInput(
      this.userInputData
    );
WuFeiyang's avatar
WuFeiyang committed
150 151
  }

152
  samplePoke(sample: any) {
153
    var samplePath = sample.CFET2CORE_SAMPLE_PATH;
154
    var pokedPath: string;
WuFeiyang's avatar
WuFeiyang committed
155
    pokedPath = samplePath;
156
    var count: number = 0;
WuFeiyang's avatar
WuFeiyang committed
157

158
    var temp = sample.Actions.get.Parameters;
WuFeiyang's avatar
WuFeiyang committed
159 160
    temp = JSON.parse(JSON.stringify(temp));
    temp = this.strMapObjChange.objToStrMap(temp);
161
    var Parameters: Map<string, string>;
162
    Parameters = temp;
WuFeiyang's avatar
WuFeiyang committed
163

164 165 166 167 168 169
    Parameters.forEach((value, key) => {
      count++;
      if (count == 1) {
        pokedPath = pokedPath + "?";
      }
      pokedPath = pokedPath + key + "=$" + key + "$&";
WuFeiyang's avatar
WuFeiyang committed
170
    });
171

172 173
    if (count != 0) {
      pokedPath = pokedPath.substring(0, pokedPath.length - 1);
WuFeiyang's avatar
WuFeiyang committed
174
    }
WuFeiyang's avatar
WuFeiyang committed
175 176 177
    this.config.data.url = pokedPath;
  }

178
  pathPoke() {
WuFeiyang's avatar
WuFeiyang committed
179
    var pokepath = this.config.data.url;
WuFeiyang's avatar
WuFeiyang committed
180 181 182 183 184 185
    axios.get(pokepath, {
        headers: {
          'Pragma': 'no-cache',
          'Cache-Control': 'no-cache'
        }
      }).then(response => {
186 187 188
      this.samplePoke(response.data);
      this.updateUI();
    });
WuFeiyang's avatar
WuFeiyang committed
189 190
  }

191 192
  replaceStartPath(startPath: string): void {
    this.config.data.url.replace("$startPath$", startPath);
WuFeiyang's avatar
WuFeiyang committed
193 194
  }

WuFeiyang's avatar
WuFeiyang committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  parentUpdate(payload: UpdatePayload): void {
    this.userInputData = this.strMapObjChange.strMapToObj(
      (this.$refs.WidgetParams as WidgetParams).getVariableValues());
      var temp = this.userInputData;
      temp = JSON.parse(JSON.stringify(temp));
      temp = this.strMapObjChange.objToStrMap(temp);
      this.userInputData = temp;
      console.log(this.userInputData);
      console.log(payload.variables);
      this.userInputData.forEach((value , key) =>{
        payload.variables.forEach((valueofpayload,keyofpayload)=>{
        if(key == keyofpayload)
        {
          this.userInputData.set(key,payload.variables.get(keyofpayload) as string);
        }
      });
    });
     (this.$refs.WidgetParams as WidgetParams).setVariableInput(this.userInputData);
WuFeiyang's avatar
WuFeiyang committed
213
    //  this.updateUI();
WuFeiyang's avatar
WuFeiyang committed
214
  }
WuFeiyang's avatar
WuFeiyang committed
215

WuFeiyang's avatar
WuFeiyang committed
216 217 218 219 220 221 222 223 224 225 226
  refresh() {
    var Args: UpdatePayload = {
      action: "get",
      variables: (this.$refs.WidgetParams as WidgetParams).getVariableValues(),
      target: ["self"]
    };
    this.viewLoad(Args);
  }

  async getData(url: string) {
    var apiLoad = url;
WuFeiyang's avatar
WuFeiyang committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240
    await axios
      .get(apiLoad, {
        headers: {
          Pragma: "no-cache",
          "Cache-Control": "no-cache"
        }
      })
      .then(response => {
        this.StatusValue = response.data.CFET2CORE_SAMPLE_VAL;
        if(this.StatusValue == undefined)
        {
            this.StatusValue = "undefined";
        }
      });
WuFeiyang's avatar
WuFeiyang committed
241 242 243 244 245 246
  }

  //called when widgetParams action clicked
  async viewLoad(Args: UpdatePayload) {
    // this.config.data.userInputData = Args.variables;
    this.userInputData = Args.variables;
WuFeiyang's avatar
WuFeiyang committed
247
    this.pathwithVar = this.pathProcessor.FillPathWithVar(
WuFeiyang's avatar
WuFeiyang committed
248 249 250 251
      // this.config.data.userInputData,
      this.userInputData,
      this.config.data.url
    );
WuFeiyang's avatar
WuFeiyang committed
252
    await this.getData(this.pathwithVar);
WuFeiyang's avatar
WuFeiyang committed
253 254 255 256 257 258 259 260 261 262
  }
}
</script>

<style scoped>
.waveView {
  width: 100%;
  height: auto;
}
</style>