config.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template lang="html">
  2. <form>
  3. <div class="container" id="config">
  4. <div class="form-group row">
  5. <label class="col-2 col-form-label">Update Interval</label>
  6. <div class="col-10">
  7. <input v-model="updateInterval" class="form-control" type="Number">
  8. </div>
  9. </div>
  10. <div class="form-group row">
  11. <label class="col-2 col-form-label">Port</label>
  12. <div class="col-10">
  13. <input v-model="options.port" class="form-control" type="number">
  14. </div>
  15. </div>
  16. <div class="form-group row">
  17. <label class="col-2 col-form-label">Start data collector on start?</label>
  18. <div class="col-10">
  19. <select v-model="options.updateState" class="form-control">
  20. <option value="true">Yes</option>
  21. <option value="false">No</option>
  22. </select>
  23. </div>
  24. </div>
  25. <div class="row">
  26. <button @click="send" class="btn btn-primary">Save</button>
  27. </div>
  28. </div>
  29. </form>
  30. </template>
  31. <script>
  32. import $ from "jquery";
  33. export default {
  34. data: function () {
  35. return {
  36. updateInterval: null,
  37. options: {
  38. updateInterval: null,
  39. port: null,
  40. updateState: null
  41. }
  42. }
  43. },
  44. created: function () {
  45. var self = this;
  46. $.getJSON('/api/config')
  47. .done(function (config) {
  48. self.options = config;
  49. self.updateInterval = self.options.updateInterval/(1000*60);
  50. });
  51. },
  52. methods: {
  53. send(){
  54. var self = this;
  55. self.options.updateInterval = self.updateInterval * 1000*60;
  56. var config = new XMLHttpRequest();
  57. config.open('POST', '/api/config');
  58. config.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  59. config.onreadystatechange = function () {
  60. if (config.readyState == XMLHttpRequest.DONE &&
  61. config.status === 200) {
  62. // self.$router.push("/");
  63. console.log(JSON.parse(config.response));
  64. }
  65. };
  66. config.send($.param(self.options));
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="css">
  72. </style>