mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-11 17:00:41 +08:00
Merge pull request #8250 from andrej-scinote/aj_SCI_11446
Add recently used forms to step in insert form modal [SCI-11446]
This commit is contained in:
commit
caff6ee1e9
4 changed files with 45 additions and 1 deletions
|
|
@ -70,6 +70,20 @@ class FormsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def latest_attached_forms
|
||||||
|
forms = current_team.forms.active.readable_by_user(current_user).published
|
||||||
|
.joins(:form_responses)
|
||||||
|
.where(form_responses: { created_by: current_user })
|
||||||
|
.select('forms.id, forms.name, MAX(form_responses.created_at) AS last_response_at')
|
||||||
|
.group('forms.id')
|
||||||
|
.order('last_response_at DESC')
|
||||||
|
.limit(5)
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
data: forms
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def publish
|
def publish
|
||||||
render_403 and return unless can_publish_form?(@form)
|
render_403 and return unless can_publish_form?(@form)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,28 @@
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
<SelectDropdown
|
<SelectDropdown
|
||||||
@change="setForm"
|
@change="setForm"
|
||||||
|
:value="form"
|
||||||
:optionsUrl="formsUrl"
|
:optionsUrl="formsUrl"
|
||||||
:placeholder="i18n.t(`protocols.steps.modals.form_modal.placeholder`)"
|
:placeholder="i18n.t(`protocols.steps.modals.form_modal.placeholder`)"
|
||||||
:searchable="true"
|
:searchable="true"
|
||||||
data-e2e="e2e-DD-insertFormModal-selectForm"
|
data-e2e="e2e-DD-insertFormModal-selectForm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="recentUsedForms.length > 0" class="flex flex-col gap-2 mt-6">
|
||||||
|
<h3 class="m-0">{{ i18n.t(`protocols.steps.modals.form_modal.recently_used`) }}</h3>
|
||||||
|
<div>
|
||||||
|
<div v-for="(option, i) in recentUsedForms" :key="option.id"
|
||||||
|
@click.stop="setForm(option.id)"
|
||||||
|
class="py-2.5 px-3 rounded cursor-pointer flex items-center gap-2 shrink-0 hover:bg-sn-super-light-grey"
|
||||||
|
:class="[{
|
||||||
|
'!bg-sn-super-light-blue': form === option.id
|
||||||
|
}]"
|
||||||
|
>
|
||||||
|
<div class="truncate text-base text-sn-blue" >{{ option.name }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<p v-else >
|
<p v-else >
|
||||||
{{ i18n.t(`protocols.steps.modals.form_modal.no_forms`) }}
|
{{ i18n.t(`protocols.steps.modals.form_modal.no_forms`) }}
|
||||||
|
|
@ -55,6 +71,7 @@ import axios from '../../../../packs/custom_axios.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
published_forms_forms_path,
|
published_forms_forms_path,
|
||||||
|
latest_attached_forms_forms_path,
|
||||||
forms_path
|
forms_path
|
||||||
} from '../../../../routes.js';
|
} from '../../../../routes.js';
|
||||||
|
|
||||||
|
|
@ -63,7 +80,8 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
form: null,
|
form: null,
|
||||||
anyForms: false
|
anyForms: false,
|
||||||
|
recentUsedForms: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mixins: [modalMixin],
|
mixins: [modalMixin],
|
||||||
|
|
@ -73,12 +91,22 @@ export default {
|
||||||
},
|
},
|
||||||
formsPageUrl() {
|
formsPageUrl() {
|
||||||
return forms_path();
|
return forms_path();
|
||||||
|
},
|
||||||
|
formsRecentUsedUrl() {
|
||||||
|
return latest_attached_forms_forms_path();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
axios.get(this.formsUrl)
|
axios.get(this.formsUrl)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.anyForms = response.data.data.length > 0;
|
this.anyForms = response.data.data.length > 0;
|
||||||
|
|
||||||
|
if (this.anyForms) {
|
||||||
|
axios.get(this.formsRecentUsedUrl)
|
||||||
|
.then((responseData) => {
|
||||||
|
this.recentUsedForms = responseData.data.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
|
|
@ -3907,6 +3907,7 @@ en:
|
||||||
no_forms: "Create and publish one or request access from your team."
|
no_forms: "Create and publish one or request access from your team."
|
||||||
add_form: "Add form"
|
add_form: "Add form"
|
||||||
take_me_there: "Take me there"
|
take_me_there: "Take me there"
|
||||||
|
recently_used: "Recently used"
|
||||||
move_element:
|
move_element:
|
||||||
step:
|
step:
|
||||||
title: Move to different step
|
title: Move to different step
|
||||||
|
|
|
||||||
|
|
@ -876,6 +876,7 @@ Rails.application.routes.draw do
|
||||||
post :restore
|
post :restore
|
||||||
get :user_roles
|
get :user_roles
|
||||||
get :published_forms
|
get :published_forms
|
||||||
|
get :latest_attached_forms
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :form_fields, only: %i(create update destroy) do
|
resources :form_fields, only: %i(create update destroy) do
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue