From ef0fab0f3f0e87f48dc15e2ef58e0fc3f25eb981 Mon Sep 17 00:00:00 2001 From: Felix Wolfsteller Date: Wed, 7 Oct 2020 20:02:21 +0200 Subject: [PATCH] remove Appointments --- .../admin/appointments_controller.rb | 72 ---------------- app/models/appointment.rb | 10 --- app/models/style.rb | 1 - app/views/admin/appointments/_form.html.haml | 32 ------- app/views/admin/appointments/_table.html.haml | 30 ------- app/views/admin/appointments/edit.html.haml | 7 -- app/views/admin/appointments/index.html.haml | 23 ----- app/views/admin/appointments/new.html.haml | 10 --- app/views/admin/appointments/show.html.haml | 34 -------- app/views/admin/styles/index.html.haml | 7 +- app/views/courses/show.html.haml | 86 +------------------ app/views/pages/_appointments.html.haml | 61 ------------- app/views/pages/_course_video_row.html.haml | 5 -- app/views/styles/show.html.haml | 8 -- .../appointments_controller_test.rb | 68 --------------- test/fixtures/appointments.yml | 19 ---- test/models/appointment_test.rb | 17 ---- 17 files changed, 3 insertions(+), 487 deletions(-) delete mode 100644 app/controllers/admin/appointments_controller.rb delete mode 100644 app/models/appointment.rb delete mode 100644 app/views/admin/appointments/_form.html.haml delete mode 100644 app/views/admin/appointments/_table.html.haml delete mode 100644 app/views/admin/appointments/edit.html.haml delete mode 100644 app/views/admin/appointments/index.html.haml delete mode 100644 app/views/admin/appointments/new.html.haml delete mode 100644 app/views/admin/appointments/show.html.haml delete mode 100644 app/views/pages/_appointments.html.haml delete mode 100644 test/controllers/appointments_controller_test.rb delete mode 100644 test/fixtures/appointments.yml delete mode 100644 test/models/appointment_test.rb diff --git a/app/controllers/admin/appointments_controller.rb b/app/controllers/admin/appointments_controller.rb deleted file mode 100644 index 53c748e..0000000 --- a/app/controllers/admin/appointments_controller.rb +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Felix Wolfsteller -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -class Admin::AppointmentsController < ApplicationController - before_action :authenticate_user! - before_action :authorize_admin! - - before_action :set_appointment, only: [:show, :edit, :update, :destroy] - - # GET /appointments - def index - @future_appointments = Appointment.future - @past_appointments = Appointment.past - end - - # GET /appointments/1 - def show - end - - # GET /appointments/new - def new - @appointment = Appointment.new - end - - # GET /appointments/1/edit - def edit - end - - # POST /appointments - def create - @appointment = Appointment.new(appointment_params) - - respond_to do |format| - if @appointment.save - format.html { redirect_to admin_appointments_path, notice: t('appointment.created-success') } - else - format.html { render :new } - end - end - end - - # PATCH/PUT /appointments/1 - def update - respond_to do |format| - if @appointment.update(appointment_params) - format.html { redirect_to [:admin, @appointment], notice: t('appointment.update-success') } - else - format.html { render :edit } - end - end - end - - # DELETE /appointments/1 - def destroy - @appointment.destroy - respond_to do |format| - format.html { redirect_to admin_appointments_url, notice: t('appointment.deletion-success') } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_appointment - @appointment = Appointment.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def appointment_params - params.require(:appointment).permit(:date_from, :date_to, :course_id, :notice, :link, :info) - end -end diff --git a/app/models/appointment.rb b/app/models/appointment.rb deleted file mode 100644 index 5e45560..0000000 --- a/app/models/appointment.rb +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Felix Wolfsteller -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -class Appointment < ApplicationRecord - belongs_to :style - - scope :future, -> { where("date_from >= ?", DateTime.current) } - scope :past, -> { where("date_from < ?", DateTime.current) } -end diff --git a/app/models/style.rb b/app/models/style.rb index d648f10..9355eb4 100644 --- a/app/models/style.rb +++ b/app/models/style.rb @@ -13,7 +13,6 @@ class Style < ApplicationRecord has_many :courses has_many :lessons - has_many :appointments validates :name, presence: true, length: { minimum: 2 }, uniqueness: true diff --git a/app/views/admin/appointments/_form.html.haml b/app/views/admin/appointments/_form.html.haml deleted file mode 100644 index 8130c31..0000000 --- a/app/views/admin/appointments/_form.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -= form_for [:admin, @appointment], builder: BulmaFormBuilder::FormBuilder do |f| - - if @appointment.errors.any? - #error_explanation - %h2 - = t("errors.prohibited_from_saving", count: @appointment.errors.count) - %ul - - @appointment.errors.full_messages.each do |message| - %li= message - - .field - = f.label :date_from - = f.datetime_select :date_from, { minute_step: 5 } - .field - = f.label :date_to - = f.datetime_select :date_to, { minute_step: 5 } - -#.field - -# = f.label :lessons - -# = f.text_field :lessons - .field - = f.label :notice - = f.text_field :notice - .field - = f.label :info - = f.text_field :info - .field - = f.label :style - = f.collection_select :style, Course.all, :id, :name, prompt: t('Select Style') - .field - = f.label :link - = f.text_field :link - .actions - = f.submit 'Save', class: 'button is-link is-outlined' diff --git a/app/views/admin/appointments/_table.html.haml b/app/views/admin/appointments/_table.html.haml deleted file mode 100644 index 523700c..0000000 --- a/app/views/admin/appointments/_table.html.haml +++ /dev/null @@ -1,30 +0,0 @@ -%table.table.is-fullwidth - %thead - %tr - %th= t('Date_from') - %th= t('Date_to') - %th= t('Course') - %th= t('Notice') - %th= t('admin.appointment.info') - %th= t('Link') - %th - %th - %th - - %tbody - - appointments.each do |appointment| - %tr - %td= appointment.date_from - %td= appointment.date_to - %td - .tag.is-link - = appointment.course.name - %td= appointment.notice - %td= appointment.link - %td= appointment.info - %td= link_to t('actions.show'), [:admin, appointment] - %td= link_to t('actions.edit'), edit_admin_appointment_path(appointment) - %td= link_to t('actions.Destroy'), [:admin, appointment], method: :delete, data: { confirm: 'Are you sure?' } - -%br - diff --git a/app/views/admin/appointments/edit.html.haml b/app/views/admin/appointments/edit.html.haml deleted file mode 100644 index 2ddf491..0000000 --- a/app/views/admin/appointments/edit.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1.title Editing appointment - -= render 'form' - -= link_to 'Show', [:admin, @appointment] -\| -= link_to 'Back', admin_appointments_path diff --git a/app/views/admin/appointments/index.html.haml b/app/views/admin/appointments/index.html.haml deleted file mode 100644 index 799b909..0000000 --- a/app/views/admin/appointments/index.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -%h1.title - = t('Listing_appointments') - -%h2.title.is-5 - = t('in_future') - -- if @future_appointments.present? - = render partial: 'table', locals: {appointments: @future_appointments} -- else - = t('none') -%br -%br - -%h2.title.is-5 - = t('in_past') - -- if @past_appointments.present? - = render partial: 'table', locals: {appointments: @past_appointments} -- else - = t('none') -%br - -= link_to 'New Appointment', new_admin_appointment_path, class: 'button is-primary is-outlined' diff --git a/app/views/admin/appointments/new.html.haml b/app/views/admin/appointments/new.html.haml deleted file mode 100644 index 7ccb490..0000000 --- a/app/views/admin/appointments/new.html.haml +++ /dev/null @@ -1,10 +0,0 @@ --# SPDX-FileCopyrightText: 2020 Felix Wolfsteller --# --# SPDX-License-Identifier: AGPL-3.0-or-later - -%h1.title - = t('New appointment') - -= render 'form' - -= link_to 'Back', admin_appointments_path diff --git a/app/views/admin/appointments/show.html.haml b/app/views/admin/appointments/show.html.haml deleted file mode 100644 index 37e3e11..0000000 --- a/app/views/admin/appointments/show.html.haml +++ /dev/null @@ -1,34 +0,0 @@ --# SPDX-FileCopyrightText: 2020 Felix Wolfsteller --# --# SPDX-License-Identifier: AGPL-3.0-or-later - -%h1.title - = t('admin.appointment.title') - -%p - %b - = t('appointment.date_from') - \: - = @appointment.date_from -%p - %b=t('Date_to:') - = @appointment.date_to -%p - %b - = t('Course') - \: - = @appointment.style.name -%p - %b Notice: - = @appointment.notice -%p - %b Link: - = @appointment.link - -%section - %h2.title.is-5 - = t('attendence') - -= link_to t('Edit'), edit_admin_appointment_path(@appointment) -\| -= link_to t('Back'), admin_appointments_path diff --git a/app/views/admin/styles/index.html.haml b/app/views/admin/styles/index.html.haml index 5c3d2c1..0728538 100644 --- a/app/views/admin/styles/index.html.haml +++ b/app/views/admin/styles/index.html.haml @@ -24,8 +24,6 @@ %th= t('admin.courses.name') %th= t('admin.courses.number_lessons') %th= t('admin.courses.number_courses') - -#%th= t('admin.courses.number_appointments') - -#%th= t('admin.courses.next_appointment') %th %tbody @@ -55,6 +53,7 @@ %i.fas.fa-eye-slash %td - if style.image.attached? + -# darken out if inactive? = image_tag style.image.variant(resize_to_fill: [180,120]).processed, class: (style.active?) ? '' : 'semi-transparent' - else @@ -67,10 +66,6 @@ = style.lessons.length %td = style.courses.active.length - -#%td - -# = style.appointments.length - -#%td - -# = style.appointments.future.first&.date_from %td .buttons = link_to t('actions.show'), style, class: 'button is-small' diff --git a/app/views/courses/show.html.haml b/app/views/courses/show.html.haml index 1f14d8d..5616802 100644 --- a/app/views/courses/show.html.haml +++ b/app/views/courses/show.html.haml @@ -40,90 +40,8 @@ = @course.description %br --if @course.appointments.future.empty? -- else - .box.flame-box - %h3.title.is-4 - = t('courses.appointments.upcoming') - = render partial: 'pages/appointments', locals: { appointments: @course.appointments.future } - -%h2.title.is-4 - = t('courses.videos') - -- if @course.lessons.active.empty? - .box - =t('courses.no_lessons_yet') -- first = @course.lessons.active.rank(:row_order).first -- last = @course.lessons.active.rank(:row_order).last -- access_level = AccessState.new(current_user).level -- @course.lessons.active.rank(:row_order).each_with_index do |lesson, idx| - .box - - if lesson.preview_image.attached? && lesson.video.attached? - %article.media - %figure.media-left - - if access_level == :admin || access_level == :full || (access_level == :trial && idx < 3) - %video(controls="true" poster="#{url_for lesson.preview_image.variant(resize_to_fill: [354, 200])}" preload="metadata" id="vs-#{lesson.id}" width="354") - %source{src: rails_blob_url(lesson.video), type:"video/mp4"} - = t('no-video-support') - - elsif user_signed_in? || access_level == :trial - .image - = image_tag lesson.preview_image.variant(resize_to_fill: [354,200]).processed, - alt: t('video.image_alt', video: t('lesson.show.video'), video_title: lesson.name) - = link_to explanation_path, class: 'is-overlay has-text-centered is-vcentered columns is-flex' do - %span.icon.has-text-primary.is-large.has-text-centered.auto-margin - %i.far.fa-play-circle.fa-3x - - else - .image - = image_tag lesson.preview_image.variant(resize_to_fill: [354,200]).processed, - alt: t('video.image_alt', video: t('lesson.show.video'), video_title: lesson.name) - = link_to new_user_registration_path, class: 'is-overlay has-text-centered is-vcentered columns is-flex' do - %span.icon.has-text-primary.is-large.has-text-centered.auto-margin - %i.far.fa-play-circle.fa-3x - .media-content.is-hidden-mobile - .content - .level - .level-left - .level-item - %h3.is-title.is-7.has-text-primary - = lesson.name - - if user_admin? - .level-right - .level-item - .buttons - - if lesson != first - = link_to admin_course_lesson_position_path(lesson.course, lesson_id: lesson.id), method: :post, class: 'button is-primary is-outlined is-small' do - %span.icon.is-small.has-text-primary - %i.fas.fa-arrow-up - - if lesson != last - = link_to admin_course_lesson_position_path(lesson.course, lesson_id: lesson.id), method: :delete, class: 'button is-primary is-outlined is-small' do - %span.icon.is-small.has-text-primary - %i.fas.fa-arrow-down - = link_to edit_admin_course_lesson_path(lesson.course, lesson), class: 'button is-link is-outlined is-small' do - %span.icon.is-small - %i.fas.fa-user-shield - %span - = t('course.admin.edit-lesson') - = link_to [:admin, lesson.course, lesson], method: :delete, data: { confirm: 'Are you sure?' }, class: 'button is-link is-outlined is-small' do - %span.icon.is-small - %i.fas.fa-user-shield - %span - = t('course.admin.destroy-lesson') - = l lesson.created_at, format: '%A, %d. %B %Y' - - if lesson.video.attached? && lesson.video.metadata[:duration] - %br/ - = "%s:" % t('video.length') - = (lesson.video.metadata[:duration] / 60).round - = t('video.minutes') - .is-hidden-tablet - %h3.is-title.is-7.has-text-primary - = lesson.name - = l lesson.created_at, format: '%A, %d. %B %Y' - - if lesson.video.attached? && lesson.video.metadata[:duration] - %br/ - = "%s:" % t('video.length') - = (lesson.video.metadata[:duration] / 60).round - = t('video.minutes') - +.content + != SiteSetting['courses_general'] - if user_admin? %h2.title.is-4 diff --git a/app/views/pages/_appointments.html.haml b/app/views/pages/_appointments.html.haml deleted file mode 100644 index 96dd8fa..0000000 --- a/app/views/pages/_appointments.html.haml +++ /dev/null @@ -1,61 +0,0 @@ -- if appointments.present? - %table.table.is-fullwidth.is-striped - %thead - %tr - %th(colspan=2) - = t('appointment.timespan') - %th(colspan=1) - = t('appointment.course') - %th(colspan=1) - %th(colspan=1) - %th(colspan=1) - = t('appointment.zoom-link') - %tbody - - appointments.order(date_from: :asc).each do |appointment| - %tr - %td - %b - = l(appointment.date_from, format: '%A') - = I18n.l appointment.date_from, format: :short - = t('apointments.time.till') - = l appointment.date_to, format: '%H:%M' - %td - (#{t('in')} #{distance_of_time_in_words_to_now appointment.date_from}) - -#= time_ago_in_words appointment.date_from - %td - .tag.is-primary - = appointment.course.name - %td - = appointment.notice - %td - - if user_signed_in? && user_has_access? - = appointment.info - %td - - if user_signed_in? && user_has_access? - = link_to appointment.link, appointment.link - - elsif user_signed_in? - - if current_user.subscriptions.any? - = t('appointments.user.subscription-ended') - - else - = t('appointments.user.trial-ended') - - else - = link_to t('register_or_sign_in'), new_user_session_path, class: 'button is-primary is-outlined is-small' - - if user_admin? - = link_to t('admin.appointment.edit'), edit_admin_appointment_path(appointment), class: 'button is-link is-outlined is-small' - - - if user_admin? - %tr - %td(colspan=3) - = link_to new_admin_appointment_path, class: 'button is-link' do - %span.icon - %i.fas.fa-user-shield - %span - = t('home.appointment.new') -- else - = t('appointments.none_in_future') - - if user_admin? - %table.table.is-fullwidth - %tr - %td(colspan=3) - = link_to t('home.appointment.new'), new_admin_appointment_path, class: 'button is-link' - diff --git a/app/views/pages/_course_video_row.html.haml b/app/views/pages/_course_video_row.html.haml index 7685ad1..1ca8887 100644 --- a/app/views/pages/_course_video_row.html.haml +++ b/app/views/pages/_course_video_row.html.haml @@ -9,11 +9,6 @@ = link_to style do %h3.title.is-4.has-text-primary = style.name - - if style.appointments.future.any? - .level-right - .has-text-light - = t('course.next_appointment') - = l style.appointments.future.first.date_from - if user_admin? .level-item-right.buttons .button.is-light.is-outlined diff --git a/app/views/styles/show.html.haml b/app/views/styles/show.html.haml index 615967f..898d57d 100644 --- a/app/views/styles/show.html.haml +++ b/app/views/styles/show.html.haml @@ -61,14 +61,6 @@ %hr --if @style.appointments.future.empty? - -# -- else - .box.flame-box - %h3.title.is-4 - = t('styles.appointments.upcoming') - = render partial: 'pages/appointments', locals: { appointments: @style.appointments.future } - - if @style.courses.active.any? %section#style-courses.my-6 = render partial: 'courses' diff --git a/test/controllers/appointments_controller_test.rb b/test/controllers/appointments_controller_test.rb deleted file mode 100644 index 2635f62..0000000 --- a/test/controllers/appointments_controller_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'test_helper' - -class AppointmentsControllerTest < ActionDispatch::IntegrationTest - include Devise::Test::IntegrationHelpers - - setup do - @appointment = appointments(:appointment_one) - end - - test "should not get index unauthenticated" do - get admin_appointments_url - assert_response :redirect - end - - test "should not get index unauthorized" do - sign_in users(:user) - get admin_appointments_url - assert_response :redirect - end - - test "should get index" do - sign_in users(:admin) - get admin_appointments_url - assert_response :success - end - - test "should get new" do - sign_in users(:admin) - get new_admin_appointment_url - assert_response :success - end - - test "should create appointment and redirect to index" do - sign_in users(:admin) - assert_difference('Appointment.count') do - post admin_appointments_url, params: { appointment: { date_from: @appointment.date_from, date_to: @appointment.date_to, style_id: @appointment.style_id, link: @appointment.link, notice: @appointment.notice } } - end - - assert_redirected_to admin_appointments_url - end - - test "should show appointment" do - sign_in users(:admin) - get admin_appointment_url(@appointment) - assert_response :success - end - - test "should get edit" do - sign_in users(:admin) - get edit_admin_appointment_url(@appointment) - assert_response :success - end - - test "should update appointment" do - sign_in users(:admin) - patch admin_appointment_url(@appointment), params: { appointment: { date_from: @appointment.date_from, date_to: @appointment.date_to, style_id: @appointment.style_id, link: @appointment.link, notice: @appointment.notice } } - assert_redirected_to admin_appointment_url(@appointment) - end - - test "should destroy appointment" do - sign_in users(:admin) - assert_difference('Appointment.count', -1) do - delete admin_appointment_url(@appointment) - end - - assert_redirected_to admin_appointments_url - end -end diff --git a/test/fixtures/appointments.yml b/test/fixtures/appointments.yml deleted file mode 100644 index c8c7c57..0000000 --- a/test/fixtures/appointments.yml +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Felix Wolfsteller -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -appointment_one: - date_from: 2020-03-22 16:39:10 - date_to: 2020-03-22 16:39:10 - style: base_yoga - notice: MyString - link: https://github.com - -appointment_two: - date_from: 2021-03-22 16:39:10 - date_to: 2021-03-22 16:39:10 - style: relaxed_yoga - notice: - link: https://github.com diff --git a/test/models/appointment_test.rb b/test/models/appointment_test.rb deleted file mode 100644 index 65ac54d..0000000 --- a/test/models/appointment_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Felix Wolfsteller -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -require 'test_helper' - -class AppointmentTest < ActiveSupport::TestCase - test "scopes" do - # TODO use time jumping instead - assert_equal 1, Appointment.past.count - assert_equal 1, Appointment.future.count - - Appointment.create!(date_from: DateTime.current + 2.days, - style: styles(:base_yoga)) - assert_equal 2, Appointment.future.count - end -end