Skip to content

Commit 6cf268b

Browse files
committed
feat(FOUR-31831): review Improve Task page loading
1 parent fda4b93 commit 6cf268b

4 files changed

Lines changed: 62 additions & 14 deletions

File tree

ProcessMaker/Http/Controllers/TaskController.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,25 @@ public function edit(ProcessRequestToken $task, string $preview = '')
108108
{
109109
$task = $task->loadTokenInstance();
110110
$dataManager = new DataManager();
111-
$userHasComments = Comment::where('commentable_type', ProcessRequestToken::class)
112-
->where('commentable_id', $task->id)
113-
->where('body', 'like', '%{{' . \Auth::user()->id . '}}%')
114-
->count() > 0;
115111

116-
if (!\Auth::user()->can('update', $task) && !$userHasComments) {
117-
$this->authorize('update', $task);
112+
// $userHasComments = Comment::where('commentable_type', ProcessRequestToken::class)
113+
// ->where('commentable_id', $task->id)
114+
// ->where('body', 'like', '%{{' . \Auth::user()->id . '}}%')
115+
// ->count() > 0;
116+
117+
// if (!\Auth::user()->can('update', $task) && !$userHasComments) {
118+
// $this->authorize('update', $task);
119+
// }
120+
121+
if (!\Auth::user()->can('update', $task)) {
122+
$userHasComments = Comment::where('commentable_type', ProcessRequestToken::class)
123+
->where('commentable_id', $task->id)
124+
->where('body', 'like', '%{{' . \Auth::user()->id . '}}%')
125+
->count() > 0;
126+
127+
if (!$userHasComments) {
128+
$this->authorize('update', $task);
129+
}
118130
}
119131

120132
//Mark notification as read
@@ -178,7 +190,10 @@ public function edit(ProcessRequestToken $task, string $preview = '')
178190
]);
179191
}
180192

181-
UserResourceView::setViewed(Auth::user(), $task);
193+
// UserResourceView::setViewed(Auth::user(), $task);
194+
dispatch(function () use ($task) {
195+
UserResourceView::setViewed(Auth::user(), $task);
196+
})->afterResponse();
182197
$currentUser = Auth::user()->only([
183198
'id',
184199
'username',
@@ -189,7 +204,8 @@ public function edit(ProcessRequestToken $task, string $preview = '')
189204
'timezone',
190205
'datetime_format',
191206
]);
192-
$userConfiguration = (new UserConfigurationController())->index();
207+
//$userConfiguration = (new UserConfigurationController())->index();
208+
$userConfiguration = app(UserConfigurationController::class)->index();
193209
$hitlEnabled = config('smart-extract.hitl_enabled', false) && $isSmartExtractTask;
194210

195211
// Build the iframe source
@@ -209,9 +225,11 @@ public function edit(ProcessRequestToken $task, string $preview = '')
209225
$iframeSrc = $dashboardUrl . '?' . $queryParams;
210226
}
211227
}
228+
$canUpdateTask = Auth::user()->can('update', $task);
212229

213230
return view('tasks.edit', [
214231
'task' => $task,
232+
'canUpdateTask' => $canUpdateTask,
215233
'dueLabels' => self::$dueLabels,
216234
'manager' => $manager,
217235
'submitUrl' => $submitUrl,

resources/js/tasks/edit.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const main = new Vue({
6464
userConfiguration,
6565
urlConfiguration: "users/configuration",
6666
showTabs: true,
67+
loadedTabs: {
68+
form: true,
69+
data: false,
70+
},
6771
},
6872
computed: {
6973
taskDefinitionConfig() {
@@ -172,6 +176,14 @@ const main = new Vue({
172176
this.setAllowReassignment();
173177
},
174178
methods: {
179+
openDataTab() {
180+
if (!this.loadedTabs.data) {
181+
this.loadedTabs.data = true;
182+
}
183+
this.$nextTick(() => {
184+
this.resizeMonaco();
185+
});
186+
},
175187
defineUserConfiguration() {
176188
this.userConfiguration = JSON.parse(this.userConfiguration.ui_configuration);
177189
this.showMenu = this.userConfiguration.tasks.isMenuCollapse;
@@ -288,8 +300,13 @@ const main = new Vue({
288300
},
289301
resizeMonaco() {
290302
this.showTree = false;
291-
const editor = this.$refs.monaco.getMonaco();
292-
editor.layout({ height: window.innerHeight * 0.65 });
303+
const editor = this.$refs.monaco?.getMonaco?.();
304+
if (!editor) {
305+
return;
306+
}
307+
editor.layout({
308+
height: window.innerHeight * 0.65,
309+
});
293310
},
294311
prepareData() {
295312
this.updateRequestData = debounce(this.updateRequestData, 1000);

resources/views/layouts/layoutnext.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
{!! config('global_header') !!}
9696
<!-- End Global Header -->
9797
@endif
98+
@stack('preload')
9899
</head>
99100
<body>
100101
<a class="skip-navigation alert alert-info" role="link" href="#main" tabindex="1">@{{ __('Skip to Content') }}</a>

resources/views/tasks/edit.blade.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ function() use ($task) {
2727
], 'attributes' => 'v-cloak'])
2828
@endsection
2929
@section('content')
30+
@push('preload')
31+
<link rel="preload" href="{{ mix('js/manifest.js') }}" as="script">
32+
<link rel="preload" href="{{ mix('js/vue-vendor.js') }}" as="script">
33+
<link rel="preload" href="{{ mix('js/bootstrap-vendor.js') }}" as="script">
34+
<link rel="preload" href="{{ mix('js/fortawesome-vendor.js') }}" as="script">
35+
<link rel="preload" href="{{ mix('js/tasks/loaderEdit.js') }}" as="script">
36+
<link rel="preload" href="{{ mix('js/tasks/edit.js') }}" as="script">
37+
@endpush
3038
<div
3139
id="task"
3240
v-cloak
@@ -77,7 +85,7 @@ class="nav-link active">
7785
role="tab"
7886
aria-controls="tab-data"
7987
aria-selected="false"
80-
@click="resizeMonaco"
88+
@click="openDataTab"
8189
class="nav-link">
8290
{{__('Data')}}
8391
</a>
@@ -86,7 +94,7 @@ class="nav-link">
8694
@endcan
8795
<div id="tabContent" class="tab-content tw-flex tw-flex-col tw-grow tw-overflow-y-scroll">
8896
<div id="tab-form" role="tabpanel" aria-labelledby="tab-form" class="tab-pane active show">
89-
@can('update', $task)
97+
@if($canUpdateTask)
9098
@unless($hitlEnabled)
9199
<span v-if="tceEnableCaseNumberScreen" class="tw-block tw-gap-2 tw-mb-0 tw-px-2 tw-bg-white tw-border-l tw-border-l-[#d7dde5] tw-border-r tw-border-r-[#d7dde5]" v-cloak>
92100
<span class="tw-font-medium tw-text-[#728092] tw-text-xs">Case #:</span> <span class="tw-font-normal tw-text-[#9fa8b5] tw-text-xs">{{ $caseNumber }}</span>
@@ -113,7 +121,7 @@ class="card border-0"
113121
@else
114122
@include('tasks.partials.hitl-iframe', ['iframeSrc' => $iframeSrc ?? null])
115123
@endunless
116-
@endcan
124+
@endif
117125
<div v-if="taskHasComments">
118126
<timeline :commentable_id="task.id"
119127
commentable_type="ProcessMaker\Models\ProcessRequestToken"
@@ -126,6 +134,7 @@ class="card border-0"
126134
<div v-if="task.process_request.status === 'ACTIVE'" id="tab-data" role="tabpanel" aria-labelledby="tab-data" class="card card-body border-top-0 tab-pane p-3">
127135
<!-- data edit -->
128136
<monaco-editor
137+
v-if="loadedTabs.data"
129138
v-show="!showTree"
130139
ref="monaco"
131140
data-cy="editorViewFrame"
@@ -437,8 +446,11 @@ class="mr-2 custom-badges pl-2 pr-2 rounded-lg">
437446
);
438447
439448
const task = @json($task);
449+
//const task = @json($taskForFrontend);
450+
440451
let draftTask = task.draft;
441-
const userHasAccessToTask = {{ Auth::user()->can('update', $task) ? "true": "false" }};
452+
// const userHasAccessToTask = {{ Auth::user()->can('update', $task) ? "true": "false" }};
453+
const userHasAccessToTask = @json($canUpdateTask);
442454
const userIsAdmin = {{ Auth::user()->is_administrator ? "true": "false" }};
443455
const userIsProcessManager = {{ in_array(Auth::user()->id, $task->process?->manager_id ?? []) ? "true": "false" }};
444456
const caseNumber = @json($caseNumber);

0 commit comments

Comments
 (0)