@konfuzio/document-validation-ui 0.1.5-pre-release-1 → 0.1.5-styles-refactor

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konfuzio/document-validation-ui",
3
- "version": "0.1.5-pre-release-1",
3
+ "version": "0.1.5-styles-refactor",
4
4
  "repository": "git://github.com:konfuzio-ai/document-validation-ui.git",
5
5
  "main": "dist/app.js",
6
6
  "scripts": {
package/src/.DS_Store CHANGED
Binary file
package/src/api.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import axios from "axios";
2
- import {
3
- cacheAdapterEnhancer
4
- } from 'axios-extensions';
2
+ import { cacheAdapterEnhancer } from "axios-extensions";
5
3
 
6
4
  let HTTP, IMG_REQUEST, authToken;
7
5
  const DEFAULT_URL = "https://app.konfuzio.com";
@@ -10,40 +8,52 @@ axios.defaults.xsrfCookieName = "csrftoken";
10
8
  axios.defaults.xsrfHeaderName = "X-CSRFToken";
11
9
 
12
10
  HTTP = axios.create({
13
- baseURL: process.env.VUE_APP_API_URL || `${DEFAULT_URL}/api/v3/`
11
+ baseURL: process.env.VUE_APP_API_URL || `${DEFAULT_URL}/api/v3/`,
14
12
  });
15
13
 
16
14
  IMG_REQUEST = axios.create({
17
15
  baseURL: process.env.VUE_APP_DOCUMENT_IMAGES_URL || `${DEFAULT_URL}`,
18
16
  responseType: "blob",
19
- adapter: cacheAdapterEnhancer(axios.defaults.adapter)
17
+ adapter: cacheAdapterEnhancer(axios.defaults.adapter),
20
18
  });
21
19
 
22
20
  const setAuthToken = (token) => {
23
21
  authToken = token;
24
- }
22
+ };
25
23
 
26
24
  const getInterceptorConfig = (config) => {
27
25
  if (authToken) {
28
- config.headers['Authorization'] = `Token ${authToken}`;
26
+ config.headers["Authorization"] = `Token ${authToken}`;
29
27
  }
30
28
  return config;
31
- }
29
+ };
32
30
 
33
- HTTP.interceptors.request.use(getInterceptorConfig,
34
- error => {
35
- return Promise.reject(error);
36
- }
37
- );
31
+ HTTP.interceptors.request.use(getInterceptorConfig, (error) => {
32
+ return Promise.reject(error);
33
+ });
38
34
 
39
- IMG_REQUEST.interceptors.request.use(getInterceptorConfig,
40
- error => {
41
- return Promise.reject(error);
42
- }
43
- );
35
+ IMG_REQUEST.interceptors.request.use(getInterceptorConfig, (error) => {
36
+ return Promise.reject(error);
37
+ });
38
+
39
+ const makeImageRequest = (imageURL) => {
40
+ return new Promise((resolve, reject) => {
41
+ if (process.env.NODE_ENV === "test") {
42
+ reject("Running unit tests!");
43
+ return;
44
+ }
45
+ IMG_REQUEST.get(imageURL)
46
+ .then((response) => {
47
+ return response.data;
48
+ })
49
+ .then((myBlob) => {
50
+ resolve(myBlob);
51
+ });
52
+ });
53
+ };
44
54
 
45
55
  export default {
46
56
  HTTP,
47
- IMG_REQUEST,
48
- setAuthToken
49
- };
57
+ makeImageRequest,
58
+ setAuthToken,
59
+ };
@@ -17,11 +17,11 @@ export default {
17
17
  },
18
18
  height: {
19
19
  default: null,
20
- type: Number,
20
+ type: String,
21
21
  },
22
22
  width: {
23
23
  default: null,
24
- type: Number,
24
+ type: String,
25
25
  },
26
26
  },
27
27
  data() {
@@ -40,10 +40,8 @@ export default {
40
40
  methods: {
41
41
  loadImage() {
42
42
  if (!this.imageUrl) return;
43
- return api.IMG_REQUEST.get(this.imageUrl)
44
- .then((response) => {
45
- return response.data;
46
- })
43
+ return api
44
+ .makeImageRequest(this.imageUrl)
47
45
  .then((myBlob) => {
48
46
  this.$refs.imgTag.src = URL.createObjectURL(myBlob);
49
47
  if (this.height) {
@@ -53,6 +51,9 @@ export default {
53
51
  this.$refs.imgTag.style.width = this.width;
54
52
  }
55
53
  this.loaded = true;
54
+ })
55
+ .catch((error) => {
56
+ this.loaded = false;
56
57
  });
57
58
  },
58
59
  },