Browse Source

Add option to search without displacing

master
Radu Liviu Carjan 3 years ago
parent
commit
8a7643565c
  1. 13
      app/Http/Controllers/SearchAndDisplaceController.php
  2. 8
      app/SearchDisplace/SearchAndDisplace.php
  3. 142
      public/js/app.js
  4. 30
      resources/js/components/ProcessFile/ProcessFile.ts
  5. 25
      resources/js/components/ProcessFile/ProcessFile.vue
  6. 13
      resources/js/services/ApiService.ts

13
app/Http/Controllers/SearchAndDisplaceController.php

@ -31,11 +31,18 @@ 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'.
'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);
}

142
public/js/app.js

@ -4251,6 +4251,60 @@ 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,
'replace_with': _this5.searchersOptions[searcher.id] || ''
});
});
_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
*/
@ -4284,25 +4338,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() {
@ -4558,39 +4612,46 @@ 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;
console.log('Search only: ', searchOnly);
console.log('RESPONSE: ', response);
return _context3.abrupt("return", response.data);
case 7:
_context3.prev = 7;
_context3.t0 = _context3["catch"](0);
case 10:
_context3.prev = 10;
_context3.t0 = _context3["catch"](1);
throw _context3.t0;
case 10:
case 13:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[0, 7]]);
}, _callee3, this, [[1, 10]]);
}));
function filterDocument(_x3, _x4) {
@ -29448,13 +29509,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() {
@ -29482,6 +29536,15 @@ var render = function() {
},
proxy: true
},
{
key: "title",
fn: function() {
return [
_vm._v("\n Original document content\n ")
]
},
proxy: true
},
{
key: "content",
fn: function() {
@ -29549,15 +29612,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() {
@ -29601,7 +29655,18 @@ var render = function() {
staticClass:
"p-button-success p-button-outlined p-button-sm",
attrs: {
label: "Run filters",
label: "Run searchers",
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",
attrs: {
label: "Search and displace",
icon: "pi pi-play",
disabled: !_vm.canRunSearchers()
},
@ -29617,6 +29682,15 @@ var render = function() {
},
proxy: true
},
{
key: "title",
fn: function() {
return [
_vm._v("\n Processed document content\n ")
]
},
proxy: true
},
{
key: "content",
fn: function() {

30
resources/js/components/ProcessFile/ProcessFile.ts

@ -290,6 +290,36 @@ export default class ProcessFile extends Vue {
}
}
private async runSearchersWithoutDisplacing() {
this.processing = true;
this.processedFileContent = '';
let searchers: Array<{ key: string; replace_with: string; }> = [];
Object.values(this.selectedSearchers).forEach((searcher: any) => {
searchers.push({
'key': searcher.id,
'replace_with': this.searchersOptions[searcher.id] || ''
});
});
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
*/

25
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
@ -17,6 +13,9 @@
</template>
</Toolbar>
</template>
<template #title>
Original document content
</template>
<template #content>
<div class="md-viewer" style="text-align: start; font-size: 0.7em;">
@ -46,10 +45,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
@ -65,8 +60,17 @@
:disabled="processedFileContent == ''"
@click="downloadOdt"/>
<Button
label="Run filters"
label="Run searchers"
icon="pi pi-play"
class="p-button-success p-button-outlined p-button-sm"
:disabled="!canRunSearchers()"
@click="runSearchersWithoutDisplacing"/>
<Button
label="Search and displace"
icon="pi pi-play"
class="p-button-success p-button-outlined p-button-sm"
:disabled="!canRunSearchers()"
@ -74,6 +78,9 @@
</template>
</Toolbar>
</template>
<template #title>
Processed document content
</template>
<template #content>
<div class="md-viewer" style="text-align: start; font-size: 0.7em;">

13
resources/js/services/ApiService.ts

@ -72,17 +72,26 @@ 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; replace_with: string; }>) {
public async filterDocument(
content: string,
searchers: Array<{ key: string; replace_with: string; }>,
searchOnly: boolean = false
) {
try {
let response = await axios.post(
this.apiRoutes.searchAndDisplace,
{
'content': content,
'searchers': searchers
'searchers': searchers,
'searchOnly': searchOnly
}
);
console.log('Search only: ', searchOnly);
console.log('RESPONSE: ', response);
return response.data;
} catch (err) {
throw err;

Loading…
Cancel
Save