Processes.vue 8.55 KB
Newer Older
Andrzej Obracaj's avatar
Andrzej Obracaj committed
1
<template>
2
3
  <div class="p-4">
    <l-container class="mb-4">
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
4
5
6
7
8
9
      <l-container-title
        slot="toolbar"
        text="Processes"
        icon="network-wired"
        color="bg-pastel-purple"
      />
10
11
      <l-csv-import @on-import="onImportProcesses" />
    </l-container>
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
12
13
14
15
    <l-info-box
      class="mb-4"
      :active="processes.length > 0"
    >Right click a row to edit, delete or add a new record</l-info-box>
16
17
18
19
20
    <hot-table :data="processes" :settings="settings" ref="hot">
      <hot-column title="ID" data="id" read-only="true"></hot-column>
      <hot-column title="measurement_type" data="measurement_type_name" read-only="true"></hot-column>
      <hot-column title="measurement_method" data="measurement_method_name" read-only="true"></hot-column>
      <hot-column title="other_measurement_method" data="other_measurement_method" read-only="true"></hot-column>
Andrzej Obracaj's avatar
bug    
Andrzej Obracaj committed
21
22
      <!-- <hot-column title="sampling_method" data="sampling_method" read-only="true"></hot-column>
      <hot-column title="other_sampling_method" data="other_sampling_method" read-only="true"></hot-column> -->
23
24
25
26
27
      <hot-column title="analytical_tech" data="analytical_tech" read-only="true"></hot-column>
      <hot-column title="other_analytical_tech" data="other_analytical_tech" read-only="true"></hot-column>
      <hot-column title="sampling_equipment" data="sampling_equipment" read-only="true"></hot-column>
      <hot-column title="measurement_equipment" data="measurement_equipment_name" read-only="true"></hot-column>
      <hot-column title="equiv_demonstration" data="equiv_demonstration_name" read-only="true"></hot-column>
28
      <hot-column title="equiv_demonstration_report" data="equiv_demonstration_report" read-only="true"></hot-column>
29
30
31
32
33
34
35
36
37
38
      <hot-column title="detection_limit" data="detection_limit" read-only="true"></hot-column>
      <hot-column title="detection_limit_uom" data="detection_limit_uom_name" read-only="true"></hot-column>
      <hot-column title="uncertainty_estimate" data="uncertainty_estimate" read-only="true"></hot-column>
      <hot-column title="documentation" data="documentation" read-only="true"></hot-column>
      <hot-column title="qa_report" data="qa_report" read-only="true"></hot-column>
      <hot-column title="duration_number" data="duration_number" read-only="true"></hot-column>
      <hot-column title="duration_unit" data="duration_unit_name" read-only="true"></hot-column>
      <hot-column title="cadence_number" data="cadence_number" read-only="true"></hot-column>
      <hot-column title="cadence_unit" data="cadence_unit_name" read-only="true"></hot-column>
      <hot-column title="responsible_authority_id" data="responsible_authority" read-only="true"></hot-column>
39
      <hot-column title="other_measurement_equipment" data="other_measurement_equipment" read-only="true"></hot-column>
40
      <hot-column title="other_sampling_equipment" data="other_sampling_equipment" read-only="true"></hot-column>
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
41
42
43
44
45
    </hot-table>
    <l-l-edit
      :showing="edit"
      @save="onSaveProcesses"
      @close="edit = false"
Andrzej Obracaj's avatar
Andrzej Obracaj committed
46
      :processes="processes"
Andrzej Obracaj's avatar
Andrzej Obracaj committed
47
48
49
50
51
52
      :measurementtypes="measurementtypes"
      :measurementmethods="measurementmethods"
      :measurementequipments="measurementequipments"
      :equivalencedemonstrated="equivalencedemonstrated"
      :concentrations="concentrations"
      :times="times"
53
      :responsibleauthorities="responsibleauthorities"
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
54
      :selected="selected"
55
      :isnew="isnew"
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
56
57
    />
  </div>
Andrzej Obracaj's avatar
Andrzej Obracaj committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
</template>

<script>
import ContextMenu from "./context.menu";
import HandsontableHelper from "@/helpers/settings/handsontable";
import "handsontable/dist/handsontable.full.css";
import { HotTable, HotColumn } from "@handsontable/vue";
import Handsontable from "handsontable";
import ProcessesService from "./processes.service";

import LLEdit from "./LLEdit";

import LCsvImport from "@/components/LCsvImport";
import { LInput, LButton } from "@/components/forms";

import Notify from "@/helpers/notify";
import LInfoBox from "@/components/LInfoBox";

export default {
  name: "processes",
  components: {
    HotTable,
    HotColumn,
81
    LInput,
Andrzej Obracaj's avatar
Andrzej Obracaj committed
82
83
84
85
86
87
88
89
90
91
    LButton,
    LInfoBox,
    LLEdit,
    LCsvImport
  },
  data() {
    return {
      edit: false,
      loading: false,
      processes: [],
Andrzej Obracaj's avatar
Andrzej Obracaj committed
92
93
94
95
96
97
      measurementtypes: [],
      measurementmethods: [],
      measurementequipments: [],
      equivalencedemonstrated: [],
      concentrations: [],
      times: [],
98
      responsibleauthorities: [],
Andrzej Obracaj's avatar
Andrzej Obracaj committed
99
100
      settings: HandsontableHelper.settings(false),
      manualSelection: false,
101
      isnew: false,
Andrzej Obracaj's avatar
Andrzej Obracaj committed
102
103
104
105
106
107
108
109
110
111
      selected: {}
    };
  },
  mounted() {
    this.settings.afterSelectionEnd = this.selectRowOnly;
    this.settings.dropdownMenu = false;
    this.settings.contextMenu = ContextMenu(this);
    Notify.loadData(null, this.loadInitialData);
  },

Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
112
  methods: {
Andrzej Obracaj's avatar
Andrzej Obracaj committed
113
114
115
116
117
118
119
120
121
122
123
124
    selectRowOnly(r, c, r2, c2) {
      if (this.manualSelection) {
        this.manualSelection = false;
        return;
      }
      const hot = this.$refs.hot.hotInstance;
      hot.deselectCell();
      this.manualSelection = true;
      hot.selectCells([[r, 0, r, hot.countCols() - 1]], false, false);
    },
    async loadInitialData() {
      this.processes = await ProcessesService.processes();
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
125
126
127
128
129
130
131
      this.measurementtypes = await ProcessesService.measurementtypes();
      this.measurementmethods = await ProcessesService.measurementmethods();
      this.measurementequipments = await ProcessesService.measurementequipments();
      this.equivalencedemonstrated = await ProcessesService.equivalencedemonstrated();
      this.concentrations = await ProcessesService.concentrations();
      this.times = await ProcessesService.times();
      this.responsibleauthorities = await ProcessesService.responsibleauthorities();
132
      // debugger;
Andrzej Obracaj's avatar
Andrzej Obracaj committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
    },
    async deleteProcesses(response) {
      if (response) {
        await Notify.loadData(
          "Please wait while data is deleting",
          async () => {
            const rowsAffected = await Processes.delete(row.id);
            const activeEditor = hot.getActiveEditor();
            hot.alter("remove_row", clickedRow, 1);
          }
        );
        Notify.success("Processes deleted!");
      }
    },
    async saveProcesses(ra) {
      const rowsAffected = await ProcessesService.update(ra);
      console.log("SAVED TO DB");
150
      // debugger;
Andrzej Obracaj's avatar
Andrzej Obracaj committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
      const current = this.processes.find(n => n.id == ra.id);
      for (var prop in current) {
        if (Object.prototype.hasOwnProperty.call(current, prop)) {
          if (current[prop] != "id" && ra[prop]) {
            current[prop] = ra[prop];
          }
        }
      }
    },
    async importProcesses(file) {
      let formData = new FormData();
      formData.append("csv", file);
      await ProcessesService.import(formData);
      this.processes = await ProcessesService.processes();
      Notify.success("Processes imported!");
    },
    async onImportProcesses(file) {
      await Notify.loadData("Importing processes", this.importProcesses, file);
    },
    onEditProcesses(t, o) {
      const clickedRow = o[0].start.row;
      const hot = this.$refs.hot.hotInstance;
      const physicalIndex = hot.toPhysicalRow(clickedRow);
      let row = hot.getSourceDataAtRow(physicalIndex);
      this.selected = row;
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
176
      this.isnew = false;
Andrzej Obracaj's avatar
Andrzej Obracaj committed
177
178
      this.edit = true;
    },
179
180
181
    onNewProcesses(t, o) {
      const hot = this.$refs.hot.hotInstance;
      let row = hot.getSourceDataAtRow(0);
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
182
183
      var newRow = Object.assign({}, row);
      Object.getOwnPropertyNames(newRow).forEach(function(prop) {
184
185
        newRow[prop] = null;
      });
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
186
      newRow.id = "Id";
187
      this.selected = newRow;
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
188
      this.isnew = true;
189
      this.edit = true;
Rune Åvar Ødegård's avatar
Rune Åvar Ødegård committed
190
    },
Andrzej Obracaj's avatar
Andrzej Obracaj committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    onDeleteProcesses(t, o) {
      const clickedRow = o[0].start.row;
      const hot = this.$refs.hot.hotInstance;
      const physicalIndex = hot.toPhysicalRow(clickedRow);
      let row = hot.getSourceDataAtRow(physicalIndex);

      Notify.prompt(async response => {
        if (response) {
          await Notify.loadData(
            "Please wait while data is deleting",
            async () => {
              const rowsAffected = await ProcessesService.delete(row.id);
              const activeEditor = hot.getActiveEditor();
              hot.alter("remove_row", clickedRow, 1);
            }
          );
          Notify.success("Processes deleted!");
        }
Andrzej Obracaj's avatar
text    
Andrzej Obracaj committed
209
      }, "This will delete all data connected to this Process. <br/><br/>Do you want to continue?");
Andrzej Obracaj's avatar
Andrzej Obracaj committed
210
211
212
    },

    async onSaveProcesses(processes) {
213
      // debugger;
Andrzej Obracaj's avatar
Andrzej Obracaj committed
214
215
216
217
218
219
220
221
222
223
224
      await Notify.loadData(
        "Saving changes to Processes " + processes.id,
        this.saveProcesses,
        processes
      );
      this.selected = {};
    }
  }
};
</script>