diff --git a/app/Http/Controllers/SearchAndDisplaceController.php b/app/Http/Controllers/SearchAndDisplaceController.php index ee82b77..557fe84 100644 --- a/app/Http/Controllers/SearchAndDisplaceController.php +++ b/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); diff --git a/app/SearchDisplace/SearchAndDisplace.php b/app/SearchDisplace/SearchAndDisplace.php index 4ee4c17..99ac60b 100644 --- a/app/SearchDisplace/SearchAndDisplace.php +++ b/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); } diff --git a/public/js/app.js b/public/js/app.js index 9d3ef3e..a09c22b 100644 --- a/public/js/app.js +++ b/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() { diff --git a/resources/js/components/ProcessFile/ProcessFile.ts b/resources/js/components/ProcessFile/ProcessFile.ts index 4af3743..ea754bd 100644 --- a/resources/js/components/ProcessFile/ProcessFile.ts +++ b/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 */ diff --git a/resources/js/components/ProcessFile/ProcessFile.vue b/resources/js/components/ProcessFile/ProcessFile.vue index 0a3d3cf..4cd23ae 100644 --- a/resources/js/components/ProcessFile/ProcessFile.vue +++ b/resources/js/components/ProcessFile/ProcessFile.vue @@ -3,10 +3,6 @@