adjust capture revision

pull/663/merge
Pete Matsyburka 1 month ago
parent 41604008d1
commit 755decca27

@ -77,8 +77,6 @@ class TemplatesController < ApplicationController
WebhookUrls.enqueue_events(@template, 'template.updated') WebhookUrls.enqueue_events(@template, 'template.updated')
TemplateVersions.find_or_create_for(@template, author: current_user) if params[:revision]
head :ok head :ok
end end

@ -14,4 +14,12 @@ class TemplatesVersionsController < ApplicationController
render json: TemplateVersions.serialize(version) render json: TemplateVersions.serialize(version)
end end
def create
authorize!(:update, @template)
TemplateVersions.find_or_create_for(@template, author: current_user)
head :ok
end
end end

@ -3146,7 +3146,11 @@ export default {
const dynamicDocumentSaves = dynamicDocumentRefs.map((ref) => ref.saveBody()) const dynamicDocumentSaves = dynamicDocumentRefs.map((ref) => ref.saveBody())
Promise.all([this.save({ force: true, revision: this.withRevisions }), ...dynamicDocumentSaves]).then(() => { Promise.all([this.save({ force: true }), ...dynamicDocumentSaves]).then(() => {
if (this.withRevisions) {
this.captureRevision()
}
window.Turbo.visit(`/templates/${this.template.id}`) window.Turbo.visit(`/templates/${this.template.id}`)
}).finally(() => { }).finally(() => {
this.isSaving = false this.isSaving = false
@ -3377,7 +3381,7 @@ export default {
} }
}) })
}, },
save ({ force = false, revision = false } = {}) { save ({ force = false } = {}) {
this.pendingFieldAttachmentUuids = [] this.pendingFieldAttachmentUuids = []
if (this.beforeRevisionSnapshot) { if (this.beforeRevisionSnapshot) {
@ -3409,8 +3413,7 @@ export default {
submitters: this.template.submitters, submitters: this.template.submitters,
fields: this.template.fields, fields: this.template.fields,
variables_schema: this.template.variables_schema variables_schema: this.template.variables_schema
}, }
...(revision ? { revision: true } : {})
}), }),
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}).then(() => { }).then(() => {
@ -3419,6 +3422,12 @@ export default {
} }
}) })
}, },
captureRevision () {
return this.baseFetch(`/templates/${this.template.id}/versions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
},
onDynamicDocumentUpdate () { onDynamicDocumentUpdate () {
this.rebuildVariablesSchema() this.rebuildVariablesSchema()

@ -109,7 +109,7 @@ Rails.application.routes.draw do
resource :form, only: %i[show], controller: 'templates_form_preview' resource :form, only: %i[show], controller: 'templates_form_preview'
resource :code_modal, only: %i[show], controller: 'templates_code_modal' resource :code_modal, only: %i[show], controller: 'templates_code_modal'
resource :preferences, only: %i[show create destroy], controller: 'templates_preferences' resource :preferences, only: %i[show create destroy], controller: 'templates_preferences'
resources :versions, only: %i[index show], controller: 'templates_versions' resources :versions, only: %i[index show create], controller: 'templates_versions'
resource :share_link, only: %i[show create], controller: 'templates_share_link' resource :share_link, only: %i[show create], controller: 'templates_share_link'
resource :share_link_qr, only: %i[show], controller: 'templates_share_link_qr' resource :share_link_qr, only: %i[show], controller: 'templates_share_link_qr'
resources :recipients, only: %i[create], controller: 'templates_recipients' resources :recipients, only: %i[create], controller: 'templates_recipients'

Loading…
Cancel
Save