Browse Source

Merge

master
Orzu Ionut 3 years ago
parent
commit
07f3d14e62
  1. 18
      app/Http/Controllers/SearchAndDisplaceController.php
  2. 8
      app/SearchDisplace/SearchAndDisplace.php
  3. 149
      public/js/app.js
  4. 31
      resources/js/components/ProcessFile/ProcessFile.ts
  5. 29
      resources/js/components/ProcessFile/ProcessFile.vue
  6. 10
      resources/js/services/ApiService.ts

18
app/Http/Controllers/SearchAndDisplaceController.php

@ -30,12 +30,22 @@ class SearchAndDisplaceController extends Controller
{
request()->validate([
'content' => 'required', // String or file.
'searchers' => 'required|array', // Check if matches all rules, must have 'key' and 'replace_with'.
'searchers' => 'required|array',
'searchers.*.key' => 'required',
'searchers.*.type' => 'required|in:replace,displace',
'searchers.*.vale' => 'nullable',
'searchOnly' => 'nullable|boolean'
]);
$searchAndDisplace = new SearchAndDisplace(request()->input('content'), [
'searchers' => request()->input('searchers'),
]);
$searchOnly = request()->input('searchOnly') ?? false;
$searchAndDisplace = new SearchAndDisplace(
request()->input('content'),
[
'searchers' => request()->input('searchers'),
],
$searchOnly
);
try {
return response()->json($searchAndDisplace->execute(), 200);

8
app/SearchDisplace/SearchAndDisplace.php

@ -8,17 +8,23 @@ class SearchAndDisplace
{
protected $documentContent;
protected $info;
protected $searchOnly = false;
public function __construct($documentContent, $info)
public function __construct($documentContent, $info, $searchOnly = false)
{
$this->documentContent = $documentContent;
$this->info = $info;
$this->searchOnly = $searchOnly;
}
public function execute()
{
$searchResult = $this->search();
if ($this->searchOnly) {
return $searchResult;
}
return $this->displace($searchResult);
}

149
public/js/app.js

@ -4391,6 +4391,61 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
return runSearchers;
}()
}, {
key: "runSearchersWithoutDisplacing",
value: function () {
var _runSearchersWithoutDisplacing = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee5() {
var _this5 = this;
var searchers, response;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
this.processing = true;
this.processedFileContent = '';
searchers = [];
Object.values(this.selectedSearchers).forEach(function (searcher) {
searchers.push({
key: searcher.id,
type: _this5.searchersOptions[searcher.id].type,
value: _this5.searchersOptions[searcher.id].value || ''
});
});
_context5.prev = 4;
_context5.next = 7;
return this.$api.filterDocument(this.fileContent, searchers, true);
case 7:
response = _context5.sent;
this.processedFileContent = this.fileContent;
this.documentDiffIndexes = response;
this.createDiffPreview();
this.processing = false;
_context5.next = 17;
break;
case 14:
_context5.prev = 14;
_context5.t0 = _context5["catch"](4);
this.$emit('error', 'Server error.'); // if (isServerError(e)) {
// this.$emit('error', getServerErrorMessage(e));
// }
case 17:
case "end":
return _context5.stop();
}
}
}, _callee5, this, [[4, 14]]);
}));
function runSearchersWithoutDisplacing() {
return _runSearchersWithoutDisplacing.apply(this, arguments);
}
return runSearchersWithoutDisplacing;
}()
/**
* Create the diff preview for the document
*/
@ -4424,25 +4479,25 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
}, {
key: "downloadOdt",
value: function () {
var _downloadOdt = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee5() {
var _downloadOdt = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee6() {
var response;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee5$(_context5) {
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.next = 2;
_context6.next = 2;
return this.$api.convertFile(this.processedFileContent, this.file.id);
case 2:
response = _context5.sent;
response = _context6.sent;
window.open("".concat(window.location.origin, "/file/download/") + response.path);
case 4:
case "end":
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, this);
}, _callee6, this);
}));
function downloadOdt() {
@ -4537,7 +4592,7 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
}, {
key: "onSelectedSearchersChanged",
value: function onSelectedSearchersChanged() {
var _this5 = this;
var _this6 = this;
var selectedIds = Object.keys(this.selectedSearchers);
var optionsIds = Object.keys(this.searchersOptions);
@ -4546,9 +4601,9 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
return;
}
_this5.$set(_this5.searchersOptions, selectedId, {
type: _this5.selectedSearchers[selectedId].tag ? 'displace' : 'replace',
value: _this5.selectedSearchers[selectedId].tag ? _this5.selectedSearchers[selectedId].tag : ''
_this6.$set(_this6.searchersOptions, selectedId, {
type: _this6.selectedSearchers[selectedId].tag ? 'displace' : 'replace',
value: _this6.selectedSearchers[selectedId].tag ? _this6.selectedSearchers[selectedId].tag : ''
});
});
optionsIds.forEach(function (optionId) {
@ -4556,7 +4611,7 @@ var ProcessFile = /*#__PURE__*/function (_Vue) {
return;
}
_this5.$delete(_this5.selectedSearchers, optionId);
_this6.$delete(_this6.selectedSearchers, optionId);
});
}
}]);
@ -4769,39 +4824,44 @@ var ApiService = /*#__PURE__*/function () {
*
* @param {string} content The content of the document
* @param {Array} searchers The list of searchers and their replace values
* @param {boolean} searchOnly Whether or not to also displace the content (default yes)
*/
}, {
key: "filterDocument",
value: function () {
var _filterDocument = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee3(content, searchers) {
var response;
var searchOnly,
response,
_args3 = arguments;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
_context3.next = 3;
searchOnly = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : false;
_context3.prev = 1;
_context3.next = 4;
return axios__WEBPACK_IMPORTED_MODULE_1___default().post(this.apiRoutes.searchAndDisplace, {
'content': content,
'searchers': searchers
'searchers': searchers,
'searchOnly': searchOnly
});
case 3:
case 4:
response = _context3.sent;
return _context3.abrupt("return", response.data);
case 7:
_context3.prev = 7;
_context3.t0 = _context3["catch"](0);
case 8:
_context3.prev = 8;
_context3.t0 = _context3["catch"](1);
throw _context3.t0;
case 10:
case 11:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[0, 7]]);
}, _callee3, this, [[1, 8]]);
}));
function filterDocument(_x3, _x4) {
@ -30017,13 +30077,6 @@ var render = function() {
return [
_c("Toolbar", {
scopedSlots: _vm._u([
{
key: "left",
fn: function() {
return [_c("h3", [_vm._v("Original document content")])]
},
proxy: true
},
{
key: "right",
fn: function() {
@ -30068,6 +30121,15 @@ var render = function() {
},
proxy: true
},
{
key: "title",
fn: function() {
return [
_vm._v("\n Original document content\n ")
]
},
proxy: true
},
{
key: "content",
fn: function() {
@ -30135,15 +30197,6 @@ var render = function() {
return [
_c("Toolbar", {
scopedSlots: _vm._u([
{
key: "left",
fn: function() {
return [
_c("h3", [_vm._v("Processed document content")])
]
},
proxy: true
},
{
key: "right",
fn: function() {
@ -30183,6 +30236,17 @@ var render = function() {
on: { click: _vm.downloadOdt }
}),
_vm._v(" "),
_c("Button", {
staticClass:
"p-button-success p-button-outlined p-button-sm",
attrs: {
label: "Run search",
icon: "pi pi-play",
disabled: !_vm.canRunSearchers()
},
on: { click: _vm.runSearchersWithoutDisplacing }
}),
_vm._v(" "),
_c("Button", {
staticClass:
"p-button-success p-button-outlined p-button-sm",
@ -30203,6 +30267,15 @@ var render = function() {
},
proxy: true
},
{
key: "title",
fn: function() {
return [
_vm._v("\n Processed document content\n ")
]
},
proxy: true
},
{
key: "content",
fn: function() {

31
resources/js/components/ProcessFile/ProcessFile.ts

@ -300,6 +300,37 @@ export default class ProcessFile extends Vue {
}
}
private async runSearchersWithoutDisplacing() {
this.processing = true;
this.processedFileContent = '';
let searchers: Array<{ key: string; type: string; value: string; }> = [];
Object.values(this.selectedSearchers).forEach((searcher: any) => {
searchers.push({
key: searcher.id,
type: this.searchersOptions[searcher.id].type,
value: this.searchersOptions[searcher.id].value || ''
});
});
try {
const response = await this.$api.filterDocument(this.fileContent, searchers, true);
this.processedFileContent = this.fileContent;
this.documentDiffIndexes = response;
this.createDiffPreview();
this.processing = false;
} catch (e) {
this.$emit('error', 'Server error.');
// if (isServerError(e)) {
// this.$emit('error', getServerErrorMessage(e));
// }
}
}
/**
* Create the diff preview for the document
*/

29
resources/js/components/ProcessFile/ProcessFile.vue

@ -3,10 +3,6 @@
<Card class="p-mr-2 p-as-stretch file-card">
<template #header>
<Toolbar>
<template #left>
<h3>Original document content</h3>
</template>
<template #right>
<Button @click="onAddNewSearcher"
type="button"
@ -28,6 +24,9 @@
</template>
</Toolbar>
</template>
<template #title>
Original document content
</template>
<template #content>
<div class="md-viewer" style="text-align: start; font-size: 0.7em;">
@ -57,10 +56,6 @@
<Card class="p-mr-2 p-as-stretch file-card">
<template #header>
<Toolbar>
<template #left>
<h3>Processed document content</h3>
</template>
<template #right>
<label for="show-diff-highlight" class="switch-label">Highlight differences:</label>
<InputSwitch
@ -76,6 +71,15 @@
:disabled="processedFileContent == ''"
@click="downloadOdt"/>
<Button
label="Run search"
icon="pi pi-play"
class="p-button-success p-button-outlined p-button-sm"
:disabled="!canRunSearchers()"
@click="runSearchersWithoutDisplacing"/>
<Button
label="Run S&D"
icon="pi pi-play"
@ -85,6 +89,9 @@
</template>
</Toolbar>
</template>
<template #title>
Processed document content
</template>
<template #content>
<div class="md-viewer" style="text-align: start; font-size: 0.7em;">
@ -169,10 +176,9 @@
paginatorTemplate="CurrentPageReport FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords}"
:rowsPerPageOptions="[10,20,50]">
<Column selectionMode="multiple" headerStyle="width: 3em"></Column>
<Column field="name" header="Name" sortable></Column>
<Column field="name" header="Name" sortable></Column>
</DataTable>
<template #footer>
@ -180,7 +186,8 @@
label="Done"
icon="pi pi-check"
class="p-button-info p-button-outlined p-button-sm"
@click="toggleSearchersDialog(false)"/>
@click="toggleSearchersDialog(false)">
</Button>
</template>
</Dialog>

10
resources/js/services/ApiService.ts

@ -72,14 +72,20 @@ export default class ApiService {
*
* @param {string} content The content of the document
* @param {Array} searchers The list of searchers and their replace values
* @param {boolean} searchOnly Whether or not to also displace the content (default yes)
*/
public async filterDocument(content: string, searchers: Array<{ key: string; type: string; value: string; }>) {
public async filterDocument(
content: string,
searchers: Array<{ key: string; type: string; value: string; }>,
searchOnly: boolean = false
) {
try {
let response = await axios.post(
this.apiRoutes.searchAndDisplace,
{
'content': content,
'searchers': searchers
'searchers': searchers,
'searchOnly': searchOnly
}
);

Loading…
Cancel
Save