This commit is contained in:
		@@ -1,7 +1,19 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <b-modal id="modal-model-info" size="lg" scrollable centered :title="id" @show="updateInfo" @close="onClose" v-model="showModal">
 | 
					  <b-modal id="modal-model-info" size="lg" scrollable centered :title="modalTitle" @show="updateInfo" @close="onClose" v-model="showModal">
 | 
				
			||||||
    <div id="modal-model-info-content">
 | 
					    <div v-if="actionPending" class="text-center">
 | 
				
			||||||
 | 
					      <b-spinner />
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <div v-else id="modal-model-info-content">
 | 
				
			||||||
 | 
					      <b-table stacked :items="[info]" :fields="infoFields">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <template #cell(default)="data">
 | 
				
			||||||
 | 
					          <b-icon v-if="data.item.default" icon="check" variant="success"></b-icon>
 | 
				
			||||||
 | 
					          <b-icon v-else icon="x-square" variant="danger"></b-icon>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      </b-table>
 | 
				
			||||||
 | 
					      <b-table stacked v-if="info.details" :items="[info.details]"></b-table>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <template #modal-footer>
 | 
					    <template #modal-footer>
 | 
				
			||||||
@@ -10,7 +22,8 @@
 | 
				
			|||||||
          variant="success"
 | 
					          variant="success"
 | 
				
			||||||
          class="float-right"
 | 
					          class="float-right"
 | 
				
			||||||
          size="sm"
 | 
					          size="sm"
 | 
				
			||||||
          @click="onClickDownloadModel"
 | 
					          :href="modelDownloadUrl"
 | 
				
			||||||
 | 
					          :disabled="!modelDownloadUrl"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <b-icon icon="download"/>
 | 
					        <b-icon icon="download"/>
 | 
				
			||||||
        Download model
 | 
					        Download model
 | 
				
			||||||
@@ -20,10 +33,11 @@
 | 
				
			|||||||
          variant="success"
 | 
					          variant="success"
 | 
				
			||||||
          class="float-right"
 | 
					          class="float-right"
 | 
				
			||||||
          size="sm"
 | 
					          size="sm"
 | 
				
			||||||
          @click="onClickDownloadExtra"
 | 
					          :href="extraDownloadUrl"
 | 
				
			||||||
 | 
					          :disabled="!extraDownloadUrl"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <b-icon icon="download"/>
 | 
					        <b-icon icon="download"/>
 | 
				
			||||||
        Download weights
 | 
					        Download {{extraType}}
 | 
				
			||||||
      </b-button>
 | 
					      </b-button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <b-button
 | 
					      <b-button
 | 
				
			||||||
@@ -34,7 +48,7 @@
 | 
				
			|||||||
          @click="onClickSetAsDefault"
 | 
					          @click="onClickSetAsDefault"
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        <b-icon icon="pencil"/>
 | 
					        <b-icon icon="pencil"/>
 | 
				
			||||||
        Set as default SVM model
 | 
					        Set as default {{info.type}} model
 | 
				
			||||||
      </b-button>
 | 
					      </b-button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      <b-button
 | 
					      <b-button
 | 
				
			||||||
@@ -83,12 +97,14 @@ export default {
 | 
				
			|||||||
  data() {
 | 
					  data() {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      actionPending: false,
 | 
					      actionPending: false,
 | 
				
			||||||
      info: {}
 | 
					      info: {},
 | 
				
			||||||
 | 
					      infoFields: ['id', 'target_class_name', 'timestamp', 'default']
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    updateInfo() {
 | 
					    updateInfo() {
 | 
				
			||||||
      return new Promise((resolve, reject) => {
 | 
					      return new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
					        this.info = {}
 | 
				
			||||||
        this.actionPending = true
 | 
					        this.actionPending = true
 | 
				
			||||||
        this.$api.get(`/model/${this.type}/${this.id}`).then(({data}) => {
 | 
					        this.$api.get(`/model/${this.type}/${this.id}`).then(({data}) => {
 | 
				
			||||||
          this.info = data
 | 
					          this.info = data
 | 
				
			||||||
@@ -111,14 +127,32 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    onClose() {
 | 
					    onClose() {
 | 
				
			||||||
      this.showModal = false;
 | 
					      this.showModal = false;
 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    onClickDownloadModel() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    onClickDownloadExtra() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    onClickSetAsDefault() {
 | 
					    onClickSetAsDefault() {
 | 
				
			||||||
 | 
					      return new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
					        this.actionPending = true
 | 
				
			||||||
 | 
					        this.$api.put(`/model/${this.type}/$default`, {id: this.id}).then(() => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          this.updateInfo().then(() => { // this resets actionPending
 | 
				
			||||||
 | 
					            this.$emit("refresh")
 | 
				
			||||||
 | 
					            resolve()
 | 
				
			||||||
 | 
					          }, reject)
 | 
				
			||||||
 | 
					        }).catch((error) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          if (!error.response) {
 | 
				
			||||||
 | 
					            // network error happened
 | 
				
			||||||
 | 
					            this.$showToast("Some network error happened.\nCheck logs!")
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            // server returned bruh moment
 | 
				
			||||||
 | 
					            this.$showToast(`The server returned error: ${error.response.status} ${error.response.statusText}\n${error.response.data}`)
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          this.actionPending = false
 | 
				
			||||||
 | 
					          reject()
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    onClickDelete() {
 | 
					    onClickDelete() {
 | 
				
			||||||
@@ -134,6 +168,32 @@ export default {
 | 
				
			|||||||
      set(v) {
 | 
					      set(v) {
 | 
				
			||||||
        this.$emit("change", v)
 | 
					        this.$emit("change", v)
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    modelDownloadUrl() {
 | 
				
			||||||
 | 
					      if (("files" in this.info) && ("model" in this.info.files)) {
 | 
				
			||||||
 | 
					        return process.env.VUE_APP_API_LOCATION + this.info.files.model
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        return ""
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    extraDownloadUrl() {
 | 
				
			||||||
 | 
					      if (("files" in this.info) && (this.extraType in this.info.files)) {
 | 
				
			||||||
 | 
					        return process.env.VUE_APP_API_LOCATION + this.info.files[this.extraType]
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        return ""
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    extraType() {
 | 
				
			||||||
 | 
					      if (this.type === "svm") {
 | 
				
			||||||
 | 
					        return "means"
 | 
				
			||||||
 | 
					      } else if (this.type === "cnn") {
 | 
				
			||||||
 | 
					        return "weights"
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        return ""
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    modalTitle() {
 | 
				
			||||||
 | 
					      return `[${this.type.toUpperCase()}] ${this.id}`
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user