diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index f32e1e1e..11968e4f 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -77,6 +77,8 @@ class TemplatesController < ApplicationController WebhookUrls.enqueue_events(@template, 'template.updated') + TemplateVersions.find_or_create_for(@template, author: current_user) if params[:revision] + head :ok end diff --git a/app/controllers/templates_versions_controller.rb b/app/controllers/templates_versions_controller.rb new file mode 100644 index 00000000..c9a67b8f --- /dev/null +++ b/app/controllers/templates_versions_controller.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class TemplatesVersionsController < ApplicationController + load_and_authorize_resource :template + + def index + versions = @template.template_versions.order(id: :desc).preload(:author) + + render json: versions.as_json(TemplateVersions::SERIALIZE_PARAMS) + end + + def show + version = @template.template_versions.find(params[:id]) + + render json: TemplateVersions.serialize(version) + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js index ff617caa..af25f2b4 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -170,6 +170,8 @@ safeRegisterElement('template-builder', class extends HTMLElement { withLogo: this.dataset.withLogo !== 'false', withFieldsDetection: this.dataset.withFieldsDetection === 'true', withDetectExistingFields: this.dataset.withDetectExistingFields === 'true', + withRevisions: true, + withRevisionsMenu: this.dataset.withRevisionsMenu === 'true', editable: this.dataset.editable !== 'false', authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content, withCustomFields: true, diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index b805af92..549cb1c6 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -51,6 +51,30 @@ +