Config.vue 10.7 KB
Newer Older
WuFeiyang's avatar
WuFeiyang committed
1 2 3 4
<template>
  <b-container class="bv-example-row">
    <b-row style="margin-top:10px">
      <b-col>
5
        <span style="float:left;" class="smallFont">Path: {{ config.data.get.url }}</span>
WuFeiyang's avatar
WuFeiyang committed
6 7
      </b-col>
      <b-col>
WuFeiyang's avatar
WuFeiyang committed
8 9 10
        <b-button @click="showPathConfig" variant="primary" style="float:right">
          <span class="glyphicon glyphicon-cog"></span>
        </b-button>
WuFeiyang's avatar
WuFeiyang committed
11 12
      </b-col>
    </b-row>
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    <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">{{ getConfigValue }}</p>
        </div>
      </b-col>
    </b-row>

    <br />

    <b-row>
      <b-col>
        <b-input-group size="lg" prepend="getPath" v-show="isShowGetPath">
          <b-form-input v-model="config.data.get.url"></b-form-input>
          <b-input-group-append>
            <b-button @click="updateGetUI" text="Button" variant="primary">OK</b-button>
            <b-button variant="info" @click="getPathPoke">poke</b-button>
          </b-input-group-append>
        </b-input-group>
      </b-col>
    </b-row>

    <b-row>
      <b-col>
        <WidgetParams
          ref="WidgetGetParams"
          v-show="isShowGetParams"
          action="get"
          @updataVariables="viewGetLoad"
        ></WidgetParams>
      </b-col>
    </b-row>

    <br />

    <b-row>
      <b-col>
        <b-input-group size="lg" prepend="setPath" v-show="isShowSetPath">
          <b-form-input v-model="config.data.set.url"></b-form-input>
          <b-input-group-append>
            <b-button @click="updateSetUI" text="Button" variant="primary">OK</b-button>
            <b-button variant="info" @click="setPathPoke">poke</b-button>
          </b-input-group-append>
        </b-input-group>
      </b-col>
    </b-row>

    <b-row>
      <b-col>
        <WidgetParams
          ref="WidgetSetParams"
          v-show="isShowSetParams"
          action="set"
          @updataVariables="viewSetLoad"
        ></WidgetParams>
      </b-col>
    </b-row>

    <br />
    <b-row>
78
      <b-col>
79
        <Navigation ref="FamilyLink" :url="config.data.get.url"></Navigation>
80 81
      </b-col>
    </b-row>
WuFeiyang's avatar
WuFeiyang committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  </b-container>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Prop, Watch } from "vue-property-decorator";
import { WidgetConfig } from "@/models/WidgetConfig";
import { UpdatePayload } from "@/models/UpdatePayload";
import { Widget } from "@/models/wiget";
import { ResourceInfo } from "@/models/Customview";
import WidgetParams from "@/components/Common/WidgetParams.vue";
import axios from "axios";
import Plotly from "plotly.js";
import PathProcessor from "@/models/PathProcessor";
import StrMapObjChange from "@/models/StrMapObjChange";
import { forEach } from "typescript-collections/dist/lib/arrays";
import { map } from "d3";
100
import Navigation from "@/components/Common/Navigation.vue";
WuFeiyang's avatar
WuFeiyang committed
101 102 103

@Component({
  components: {
WuFeiyang's avatar
WuFeiyang committed
104 105
    WidgetParams,
    Navigation
WuFeiyang's avatar
WuFeiyang committed
106 107
  }
})
108
export default class Config extends Widget {
WuFeiyang's avatar
WuFeiyang committed
109 110
  pathProcessor = new PathProcessor();
  strMapObjChange = new StrMapObjChange();
111
  WidgetComponentName: string = "Config";
WuFeiyang's avatar
WuFeiyang committed
112
  getConfigValue: string = " ";
113
  setConfigValue: string = "";
WuFeiyang's avatar
WuFeiyang committed
114
  pathId: string = "";
115 116
  userGetInputData = new Map<string, string>();
  userSetInputData = new Map<string, string>();
WuFeiyang's avatar
WuFeiyang committed
117 118 119 120
  getPathwithVar: string = "";
  setPathwithVar: string = "";
  isShowGetPath: boolean = false;
  isShowSetPath: boolean = false;
121 122
  isShowGetParams: boolean = false;
  isShowSetParams: boolean = false;
WuFeiyang's avatar
WuFeiyang committed
123

WuFeiyang's avatar
WuFeiyang committed
124
  isSetPoke: boolean = false;
125
  isGetPoke: boolean = false;
WuFeiyang's avatar
WuFeiyang committed
126

WuFeiyang's avatar
WuFeiyang committed
127 128 129
  config: WidgetConfig = {
    WidgetComponentName: "Status",
    data: {
WuFeiyang's avatar
WuFeiyang committed
130 131
      get: { url: "", userInputData: "" },
      set: { url: "", userInputData: "" }
WuFeiyang's avatar
WuFeiyang committed
132 133 134 135 136
    }
  };

  created() {
    // this.config.data.userInputData = this.userInputData;
137 138 139 140 141 142
    this.config.data.get.userInputData = this.strMapObjChange.strMapToObj(
      this.userGetInputData
    );
    this.config.data.set.userInputData = this.strMapObjChange.strMapToObj(
      this.userSetInputData
    );
143 144
  }

WuFeiyang's avatar
WuFeiyang committed
145
  updateUI() {
146 147
    this.updateGetUI();
    this.updateSetUI();
WuFeiyang's avatar
WuFeiyang committed
148 149
  }

150 151
  updateGetUI() {
    this.isShowGetParams = true;
WuFeiyang's avatar
WuFeiyang committed
152
    this.isShowGetPath = false;
153
    var url = this.config.data.get.url;
WuFeiyang's avatar
WuFeiyang committed
154
    this.pathId = url.slice(0, url.indexOf("/"));
155 156 157 158 159 160 161
    (this.$refs.WidgetGetParams as WidgetParams).setVariableList(
      this.pathProcessor.extractVarFromPath(url)
    );
  }

  updateSetUI() {
    this.isShowSetParams = true;
WuFeiyang's avatar
WuFeiyang committed
162
    this.isShowSetPath = false;
163 164 165
    var url = this.config.data.set.url;
    this.pathId = url.slice(0, url.indexOf("/"));
    (this.$refs.WidgetSetParams as WidgetParams).setVariableList(
WuFeiyang's avatar
WuFeiyang committed
166 167 168 169 170
      this.pathProcessor.extractVarFromPath(url)
    );
  }

  showPathConfig() {
171 172 173 174
    if (this.isShowGetPath == this.isShowSetPath) {
      this.isShowGetPath = !this.isShowGetPath;
      this.isShowSetPath = !this.isShowSetPath;
    } else {
WuFeiyang's avatar
WuFeiyang committed
175 176 177
      this.isShowGetPath = true;
      this.isShowSetPath = true;
    }
WuFeiyang's avatar
WuFeiyang committed
178 179 180 181
  }

  getConfig(): WidgetConfig {
    // this.config.data.userInputData =(this.$refs.WidgetParams as WidgetParams).getVariableValues();
WuFeiyang's avatar
WuFeiyang committed
182 183 184 185 186 187
    this.config.data.get.userInputData = this.strMapObjChange.strMapToObj(
      (this.$refs.WidgetGetParams as WidgetParams).getVariableValues()
    );
    this.config.data.set.userInputData = this.strMapObjChange.strMapToObj(
      (this.$refs.WidgetSetParams as WidgetParams).getVariableValues()
    );
WuFeiyang's avatar
WuFeiyang committed
188 189 190 191 192 193 194
    return this.config;
  }

  setConfig(widgetConfig: WidgetConfig): void {
    this.config = widgetConfig;
    this.updateUI();
    //map不能序列化,必须要单独处理,这里的处理方法仅限map<string,string>类型
195 196 197 198 199
    //布置get输入参数
    var temp = this.config.data.get.userInputData;
    temp = JSON.parse(JSON.stringify(temp));
    temp = this.strMapObjChange.objToStrMap(temp);
    this.userGetInputData = temp;
WuFeiyang's avatar
WuFeiyang committed
200 201 202
    (this.$refs.WidgetGetParams as WidgetParams).setVariableInput(
      this.userGetInputData
    );
203 204
    //布置set输入参数
    temp = this.config.data.set.userInputData;
WuFeiyang's avatar
WuFeiyang committed
205 206
    temp = JSON.parse(JSON.stringify(temp));
    temp = this.strMapObjChange.objToStrMap(temp);
207
    this.userSetInputData = temp;
WuFeiyang's avatar
WuFeiyang committed
208 209 210
    (this.$refs.WidgetSetParams as WidgetParams).setVariableInput(
      this.userSetInputData
    );
WuFeiyang's avatar
WuFeiyang committed
211 212
  }

213
  samplePoke(sample: any) {
214
    var samplePath = sample.CFET2CORE_SAMPLE_PATH;
WuFeiyang's avatar
WuFeiyang committed
215
    var pokedPath: string;
WuFeiyang's avatar
WuFeiyang committed
216
    pokedPath = samplePath;
WuFeiyang's avatar
WuFeiyang committed
217
    var count: number = 0;
WuFeiyang's avatar
WuFeiyang committed
218

219 220 221 222
    if (this.isSetPoke == false || this.isGetPoke == true) {
      var temp = sample.Actions.get.Parameters;
      temp = JSON.parse(JSON.stringify(temp));
      temp = this.strMapObjChange.objToStrMap(temp);
223
      var Parameters: Map<string, string>;
224 225
      Parameters = temp;

226 227 228 229 230 231
      Parameters.forEach((value, key) => {
        count++;
        if (count == 1) {
          pokedPath = pokedPath + "?";
        }
        pokedPath = pokedPath + key + "=$" + key + "$&";
WuFeiyang's avatar
WuFeiyang committed
232
      });
233

234 235
      if (count != 0) {
        pokedPath = pokedPath.substring(0, pokedPath.length - 1);
236
      }
WuFeiyang's avatar
WuFeiyang committed
237
      this.config.data.get.url = pokedPath;
238 239
    }

240
    if (this.isGetPoke == false || this.isSetPoke == true) {
WuFeiyang's avatar
WuFeiyang committed
241 242
      pokedPath = samplePath;
      count = 0;
WuFeiyang's avatar
WuFeiyang committed
243

244 245 246
      var settemp = sample.Actions.set.Parameters;
      settemp = JSON.parse(JSON.stringify(settemp));
      settemp = this.strMapObjChange.objToStrMap(settemp);
247
      var SetParameters: Map<string, string>;
248
      SetParameters = settemp;
249

250 251 252 253 254 255
      SetParameters.forEach((value, key) => {
        count++;
        if (count == 1) {
          pokedPath = pokedPath + "?";
        }
        pokedPath = pokedPath + key + "=$" + key + "$&";
WuFeiyang's avatar
WuFeiyang committed
256
      });
257

258 259
      if (count != 0) {
        pokedPath = pokedPath.substring(0, pokedPath.length - 1);
260
      }
WuFeiyang's avatar
WuFeiyang committed
261 262 263
      this.config.data.set.url = pokedPath;
    }
    this.isSetPoke = false;
264
    this.isGetPoke = false;
WuFeiyang's avatar
WuFeiyang committed
265
  }
266

267 268 269 270 271 272 273 274 275
  getPathPoke() {
    var f = this.config.data.get.url;
    var pokepath = "a";
    pokepath = f;
    axios.get(pokepath).then(response => {
      this.isGetPoke = true;
      this.samplePoke(response.data);
      this.updateUI();
    });
WuFeiyang's avatar
WuFeiyang committed
276 277
  }

278 279 280 281 282 283 284 285 286
  setPathPoke() {
    var f = this.config.data.set.url;
    var pokepath = "a";
    pokepath = f;
    axios.get(pokepath).then(response => {
      this.isSetPoke = true;
      this.samplePoke(response.data);
      this.updateUI();
    });
WuFeiyang's avatar
WuFeiyang committed
287 288
  }

WuFeiyang's avatar
WuFeiyang committed
289 290 291
  pathPoke() {
    this.getPathPoke();
    this.setPathPoke();
WuFeiyang's avatar
WuFeiyang committed
292 293
  }

WuFeiyang's avatar
WuFeiyang committed
294 295 296
  replaceStartPath(startPath: string): void {
    this.config.data.get.url.replace("$startPath$", startPath);
    this.config.data.set.url.replace("$startPath$", startPath);
WuFeiyang's avatar
WuFeiyang committed
297 298
  }

WuFeiyang's avatar
WuFeiyang committed
299 300
  parentUpdate(payload: UpdatePayload): void {}

WuFeiyang's avatar
WuFeiyang committed
301
  refresh() {
302
    var GetArgs: UpdatePayload = {
WuFeiyang's avatar
WuFeiyang committed
303
      action: "get",
WuFeiyang's avatar
WuFeiyang committed
304 305
      variables: (this.$refs
        .WidgetGetParams as WidgetParams).getVariableValues(),
WuFeiyang's avatar
WuFeiyang committed
306 307
      target: ["self"]
    };
308 309 310 311
    this.viewGetLoad(GetArgs);

    var SetArgs: UpdatePayload = {
      action: "set",
WuFeiyang's avatar
WuFeiyang committed
312 313
      variables: (this.$refs
        .WidgetSetParams as WidgetParams).getVariableValues(),
314 315 316
      target: ["self"]
    };
    this.viewSetLoad(SetArgs);
WuFeiyang's avatar
WuFeiyang committed
317 318 319 320
  }

  async getData(url: string) {
    var apiLoad = url;
WuFeiyang's avatar
WuFeiyang committed
321 322 323 324 325 326
    await axios.get(apiLoad, {
        headers: {
          'Pragma': 'no-cache',
          'Cache-Control': 'no-cache'
        }
      }).then(response => {
327
      this.getConfigValue = response.data.CFET2CORE_SAMPLE_VAL;
WuFeiyang's avatar
WuFeiyang committed
328 329 330 331
      if(this.getConfigValue == undefined)
      {
          this.getConfigValue = "undefined";
      }
332 333 334 335 336 337
      console.log(this.getConfigValue);
    });
  }

  async setData(url: string) {
    var apiLoad = url;
WuFeiyang's avatar
WuFeiyang committed
338 339 340 341 342 343
    await axios.post(apiLoad, {
        headers: {
          'Pragma': 'no-cache',
          'Cache-Control': 'no-cache'
        }
      }).then(response => {
344
      this.setConfigValue = response.data.CFET2CORE_SAMPLE_VAL;
WuFeiyang's avatar
WuFeiyang committed
345 346 347 348
    });
  }

  //called when widgetParams action clicked
349 350 351 352 353 354 355 356 357 358 359 360
  async viewGetLoad(Args: UpdatePayload) {
    // this.config.data.userInputData = Args.variables;
    this.userGetInputData = Args.variables;
    this.getPathwithVar = this.pathProcessor.FillPathWithVar(
      // this.config.data.userInputData,
      this.userGetInputData,
      this.config.data.get.url
    );
    await this.getData(this.getPathwithVar);
  }

  async viewSetLoad(Args: UpdatePayload) {
WuFeiyang's avatar
WuFeiyang committed
361
    // this.config.data.userInputData = Args.variables;
362 363
    this.userSetInputData = Args.variables;
    this.setPathwithVar = this.pathProcessor.FillPathWithVar(
WuFeiyang's avatar
WuFeiyang committed
364
      // this.config.data.userInputData,
365 366
      this.userSetInputData,
      this.config.data.set.url
WuFeiyang's avatar
WuFeiyang committed
367
    );
368
    await this.setData(this.setPathwithVar);
WuFeiyang's avatar
WuFeiyang committed
369
    this.getrefresh();
WuFeiyang's avatar
WuFeiyang committed
370
  }
WuFeiyang's avatar
WuFeiyang committed
371 372 373 374 375 376 377 378 379 380 381

    getrefresh() {
    var GetArgs: UpdatePayload = {
      action: "get",
      variables: (this.$refs
        .WidgetGetParams as WidgetParams).getVariableValues(),
      target: ["self"]
    };
    this.viewGetLoad(GetArgs);
  }

WuFeiyang's avatar
WuFeiyang committed
382 383 384 385 386 387 388 389 390
}
</script>

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