Browse Source

Fix various issues

master
Orzu Ionut 3 years ago
parent
commit
3f2ed6c3fd
  1. 11
      app/Http/Controllers/SearchAndDisplaceController.php
  2. 16
      app/SearchDisplace/Documents/DocumentFile.php
  3. 10
      app/SearchDisplace/Searchers/Searcher.php
  4. 269
      public/js/app.js
  5. 18
      resources/js/SearchDisplace/helpers.ts
  6. 5
      resources/js/components/Home/Home.ts
  7. 76
      resources/js/components/Home/Home.vue
  8. 69
      resources/js/components/ProcessFile/ProcessFile.ts
  9. 4
      resources/js/components/ProcessFile/ProcessFile.vue
  10. 6
      resources/js/interfaces/responses/FileStatusResponse.ts

11
app/Http/Controllers/SearchAndDisplaceController.php

@ -12,14 +12,13 @@ class SearchAndDisplaceController extends Controller
$handler = new DocumentFile();
try {
$documentContent = $handler->getAfterIngest($id);
$result = $handler->getAfterIngest($id);
$handler->destroy($id);
if ($result['status'] !== 'processing') {
$handler->destroy($id);
}
return response()->json([
'content' => $documentContent,
'ingest_status' => !! $documentContent ? 'success' : 'fail',
], 200);
return response()->json($result, 200);
} catch (\Exception $exception) {
return response()->json([
'message' => $exception->getMessage(),

16
app/SearchDisplace/Documents/DocumentFile.php

@ -19,15 +19,23 @@ class DocumentFile
// Ingest success.
if ($this->storage->exists("$path.md")) {
return $this->storage->get("$path.md");
return [
'status' => 'success',
'content' => $this->storage->get("$path.md"),
];
}
// Ingest fail.
if ($this->storage->exists($path)) {
return '';
return [
'status' => 'fail',
];
}
throw new \Exception('Document has not been processed yet.');
return [
'status' => 'processing',
'message' => 'Document has not been processed yet.',
];
}
public function destroy($id)
@ -44,7 +52,7 @@ class DocumentFile
return $this->storage->delete($path);
}
throw new \Exception('Document has not been processed yet.');
return false;
}
protected function getPath($id)

10
app/SearchDisplace/Searchers/Searcher.php

@ -179,13 +179,21 @@ class Searcher
return [];
}
return array_map(function ($item) {
$results = array_map(function ($item) {
if ( ! $item[0]) {
return [];
}
return [
'start' => $item[1],
'end' => $item[1] + strlen($item[0]) - 1,
'content' => $item[0],
];
}, $matches[0]);
return array_filter($results, function ($result) {
return count($result) > 0;
});
}
protected function processResults($results)

269
public/js/app.js

@ -3383,6 +3383,7 @@ var Home = /*#__PURE__*/function (_Vue) {
id: '',
file_name: ''
};
_this.error = '';
return _this;
}
/**
@ -3448,6 +3449,11 @@ var Home = /*#__PURE__*/function (_Vue) {
return uploadFile;
}()
}, {
key: "onError",
value: function onError(error) {
this.error = error;
}
}]);
return Home;
@ -3642,7 +3648,7 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
key: "waitForFile",
value: function () {
var _waitForFile = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee() {
var response;
var response, error;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
@ -3653,27 +3659,38 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
case 2:
response = _context.sent;
if (response.content !== null) {
if (response.ingest_status === 'fail') {
this.$toast.add({
severity: 'error',
summary: 'File error',
detail: 'THere was an error processing the file in ingest',
life: 3000
});
} else {
this.fileContent = response.content;
this.$toast.add({
severity: 'success',
summary: 'File loaded',
detail: 'The file has been processed by ingest.',
life: 3000
});
clearInterval(this.intervalId);
}
if (!(response.status === 'processing')) {
_context.next = 5;
break;
}
case 4:
return _context.abrupt("return");
case 5:
clearInterval(this.intervalId);
if (response.status === 'success') {
this.fileContent = response.content ? response.content : '';
this.$toast.add({
severity: 'success',
summary: 'File loaded',
detail: 'The file has been processed by ingest.',
life: 3000
});
}
if (response.status === 'fail') {
error = 'There was an error processing the file in ingest';
this.$toast.add({
severity: 'error',
summary: 'File error',
detail: error,
life: 3000
});
this.$emit('error', error);
}
case 8:
case "end":
return _context.stop();
}
@ -3726,22 +3743,32 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
'replace_with': _this2.searchersOptions[searcher.id] || ''
});
});
_context2.next = 6;
_context2.prev = 4;
_context2.next = 7;
return this.$api.filterDocument(this.fileContent, searchers);
case 6:
case 7:
response = _context2.sent;
this.processedFileContent = response.content;
this.documentDiffIndexes = response.indexes;
this.createDiffPreview();
this.processing = false;
_context2.next = 17;
break;
case 11:
case 14:
_context2.prev = 14;
_context2.t0 = _context2["catch"](4);
this.$emit('error', 'Server error.'); // if (isServerError(e)) {
// this.$emit('error', getServerErrorMessage(e));
// }
case 17:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}, _callee2, this, [[4, 14]]);
}));
function runSearchers() {
@ -27997,85 +28024,111 @@ var render = function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return !_vm.fileUploaded && !_vm.uploading
? _c(
"div",
{ staticClass: "wrap" },
[
_c(
"Panel",
{ attrs: { header: "Please upload a file" } },
[
_c("FileUpload", {
attrs: { name: "demo[]", customUpload: true, auto: true },
on: { uploader: _vm.uploadFile },
scopedSlots: _vm._u(
[
{
key: "empty",
fn: function() {
return [
_c("p", [
_vm._v("Drag and drop files to here to upload.")
])
]
},
proxy: true
}
],
null,
false,
4144631135
)
})
],
1
),
_vm._v(" "),
_c("BlockUI", { attrs: { blocked: _vm.uiBlocked, fullScreen: true } })
],
1
)
: !_vm.fileUploaded && _vm.uploading
? _c(
"div",
{ staticClass: "wrap" },
[
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br")
],
1
)
: _c(
"div",
{ staticClass: "wrap" },
[
_c("process-file", {
attrs: { file: _vm.uploadResult, searchers: _vm.searchers }
})
],
1
)
return _c(
"div",
{ staticClass: "wrap" },
[
!_vm.error
? [
!_vm.fileUploaded
? [
!_vm.uploading
? [
_c(
"Panel",
{ attrs: { header: "Please upload a file" } },
[
_c("FileUpload", {
attrs: {
name: "demo[]",
customUpload: true,
auto: true
},
on: { uploader: _vm.uploadFile },
scopedSlots: _vm._u(
[
{
key: "empty",
fn: function() {
return [
_c("p", [
_vm._v(
"Drag and drop files to here to upload."
)
])
]
},
proxy: true
}
],
null,
false,
4144631135
)
})
],
1
),
_vm._v(" "),
_c("BlockUI", {
attrs: { blocked: _vm.uiBlocked, fullScreen: true }
})
]
: [
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br"),
_vm._v(" "),
_c("Skeleton"),
_c("br")
]
]
: [
_c("process-file", {
attrs: { file: _vm.uploadResult, searchers: _vm.searchers },
on: { error: _vm.onError }
})
]
]
: [
_c("h1", [_vm._v(" Something went wrong while processing. ")]),
_vm._v(" "),
_c("p", [_vm._v(" " + _vm._s(_vm.error) + " ")]),
_vm._v(" "),
_vm._m(0)
]
],
2
)
}
var staticRenderFns = []
var staticRenderFns = [
function() {
var _vm = this
var _h = _vm.$createElement
var _c = _vm._self._c || _h
return _c("a", { attrs: { href: "/" } }, [
_c(
"button",
{ staticClass: "p-button p-button-primary", attrs: { type: "button" } },
[_vm._v("\n Try another file\n ")]
)
])
}
]
render._withStripped = true
@ -28236,11 +28289,7 @@ var render = function() {
icon: "pi pi-download",
disabled: _vm.processedFileContent == ""
},
on: {
click: function($event) {
return _vm.downloadOdt()
}
}
on: { click: _vm.downloadOdt }
}),
_vm._v(" "),
_c("Button", {
@ -28253,11 +28302,7 @@ var render = function() {
_vm.fileContent == "" ||
_vm.selectedSearchers.length === 0
},
on: {
click: function($event) {
return _vm.runSearchers()
}
}
on: { click: _vm.runSearchers }
})
]
},

18
resources/js/SearchDisplace/helpers.ts

@ -0,0 +1,18 @@
export function isServerError(e: any) {
return e &&
typeof (e) === 'object' &&
e.hasOwnProperty('response') &&
e.response &&
e.response.hasOwnProperty('data') &&
e.response.data;
}
export function getServerErrorMessage(e: any) {
const error = e.response.data;
if (error.hasOwnProperty('message')) {
return error.message;
}
return '';
}

5
resources/js/components/Home/Home.ts

@ -13,6 +13,7 @@ export default class Home extends Vue {
id: '',
file_name: '',
};
public error: string = '';
/**
* A method which uploads the files to the server for processing
@ -46,4 +47,8 @@ export default class Home extends Vue {
this.fileUploaded = false;
}
}
public onError(error: string) {
this.error = error;
}
}

76
resources/js/components/Home/Home.vue

@ -1,33 +1,55 @@
<template>
<div class="wrap" v-if="!fileUploaded && !uploading">
<Panel header="Please upload a file">
<FileUpload
name="demo[]"
:customUpload="true"
:auto="true"
@uploader="uploadFile"
>
<template #empty>
<p>Drag and drop files to here to upload.</p>
<div class="wrap">
<template v-if=" ! error">
<template v-if=" ! fileUploaded">
<template v-if=" ! uploading">
<Panel header="Please upload a file">
<FileUpload
name="demo[]"
:customUpload="true"
:auto="true"
@uploader="uploadFile"
>
<template #empty>
<p>Drag and drop files to here to upload.</p>
</template>
</FileUpload>
</Panel>
<BlockUI :blocked="uiBlocked" :fullScreen="true"></BlockUI>
</template>
</FileUpload>
</Panel>
<BlockUI :blocked="uiBlocked" :fullScreen="true"></BlockUI>
</div>
<div class="wrap" v-else-if="!fileUploaded && uploading">
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
</div>
<div class="wrap" v-else>
<process-file :file="uploadResult" :searchers="searchers"></process-file>
<template v-else>
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
<Skeleton /><br />
</template>
</template>
<template v-else>
<process-file :file="uploadResult"
:searchers="searchers"
@error="onError">
</process-file>
</template>
</template>
<template v-else>
<h1> Something went wrong while processing. </h1>
<p> {{ error }} </p>
<a href="/">
<button type="button" class="p-button p-button-primary">
Try another file
</button>
</a>
</template>
</div>
</template>
<script lang="ts" src="./Home.ts">
</script>
<script lang="ts" src="./Home.ts"></script>

69
resources/js/components/ProcessFile/ProcessFile.ts

@ -1,6 +1,7 @@
import marked from 'marked';
import {Vue, Component, Prop, Watch} from 'vue-property-decorator';
import {FileData} from '@/interfaces/FileData';
import { isServerError, getServerErrorMessage } from '@/SearchDisplace/helpers';
@Component
export default class ProcessFile extends Vue {
@ -122,30 +123,36 @@ export default class ProcessFile extends Vue {
* Wait for the file to be processed in ingest
*/
private async waitForFile() {
const response = await this.$api.getFileData(this.file.id);
if (response.content !== null) {
if (response.ingest_status === 'fail') {
this.$toast.add({
severity: 'error',
summary: 'File error',
detail: 'THere was an error processing the file in ingest',
life: 3000
});
} else {
this.fileContent = response.content;
this.$toast.add({
severity: 'success',
summary: 'File loaded',
detail: 'The file has been processed by ingest.',
life: 3000
});
clearInterval(this.intervalId);
}
if (response.status === 'processing') {
return;
}
clearInterval(this.intervalId);
if (response.status === 'success') {
this.fileContent = response.content ? response.content : '';
this.$toast.add({
severity: 'success',
summary: 'File loaded',
detail: 'The file has been processed by ingest.',
life: 3000
});
}
if (response.status === 'fail') {
const error = 'There was an error processing the file in ingest';
this.$toast.add({
severity: 'error',
summary: 'File error',
detail: error,
life: 3000
});
this.$emit('error', error);
}
}
@ -177,13 +184,21 @@ export default class ProcessFile extends Vue {
});
});
const response = await this.$api.filterDocument(this.fileContent, searchers);
try {
const response = await this.$api.filterDocument(this.fileContent, searchers);
this.processedFileContent = response.content;
this.documentDiffIndexes = response.indexes;
this.createDiffPreview();
this.processedFileContent = response.content;
this.documentDiffIndexes = response.indexes;
this.createDiffPreview();
this.processing = false;
} catch (e) {
this.$emit('error', 'Server error.');
this.processing = false;
// if (isServerError(e)) {
// this.$emit('error', getServerErrorMessage(e));
// }
}
}
/**

4
resources/js/components/ProcessFile/ProcessFile.vue

@ -54,14 +54,14 @@
icon="pi pi-download"
class="p-button-secondary p-button-outlined p-button-sm"
:disabled="processedFileContent == ''"
@click="downloadOdt()"/>
@click="downloadOdt"/>
<Button
label="Run filters"
icon="pi pi-play"
class="p-button-success p-button-outlined p-button-sm"
:disabled="fileContent == '' || selectedSearchers.length === 0"
@click="runSearchers()"/>
@click="runSearchers"/>
</template>
</Toolbar>
</template>

6
resources/js/interfaces/responses/FileStatusResponse.ts

@ -1,5 +1,5 @@
export default interface FileStatusResponse
{
content: string;
ingest_status: string;
}
content?: string;
status: string;
}
Loading…
Cancel
Save