diff --git a/app/Http/Controllers/SearchAndDisplaceController.php b/app/Http/Controllers/SearchAndDisplaceController.php index ee82b77..6b0482b 100644 --- a/app/Http/Controllers/SearchAndDisplaceController.php +++ b/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); diff --git a/app/SearchDisplace/SearchAndDisplace.php b/app/SearchDisplace/SearchAndDisplace.php index 8039c34..be86846 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 52b75b2..53a7bbe 100644 --- a/public/js/app.js +++ b/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() { diff --git a/resources/js/components/ProcessFile/ProcessFile.ts b/resources/js/components/ProcessFile/ProcessFile.ts index c9ee189..23fcb74 100644 --- a/resources/js/components/ProcessFile/ProcessFile.ts +++ b/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 */ diff --git a/resources/js/components/ProcessFile/ProcessFile.vue b/resources/js/components/ProcessFile/ProcessFile.vue index 9349ca2..2f6ee4d 100644 --- a/resources/js/components/ProcessFile/ProcessFile.vue +++ b/resources/js/components/ProcessFile/ProcessFile.vue @@ -3,10 +3,6 @@