From 26f7d2755b5bfae1066b08f7ecb6066a74fe068d Mon Sep 17 00:00:00 2001 From: Bert Owen Date: Mon, 14 Jul 2014 20:40:00 +0200 Subject: [PATCH] VRFS-1918 Session Details Update Screen - once over with tests --- ruby/lib/jam_ruby/models/music_session.rb | 29 +++++++- .../accounts_session_properties.js | 70 ++++++++++++++++--- .../assets/javascripts/scheduled_session.js | 2 +- .../stylesheets/client/account.css.scss | 40 ++++++++++- web/app/helpers/music_session_helper.rb | 4 +- .../api_music_sessions/show_history.rabl | 8 +-- .../_account_session_properties.html.haml | 16 ++++- web/spec/features/account_spec.rb | 53 ++++++++++++-- 8 files changed, 195 insertions(+), 27 deletions(-) diff --git a/ruby/lib/jam_ruby/models/music_session.rb b/ruby/lib/jam_ruby/models/music_session.rb index 4dff65765..603109279 100644 --- a/ruby/lib/jam_ruby/models/music_session.rb +++ b/ruby/lib/jam_ruby/models/music_session.rb @@ -743,9 +743,34 @@ module JamRuby result end + def scheduled_start_date + if self.scheduled_start_time.blank? + "" + else + self.scheduled_start.strftime "%a %e %B %Y" + end + end + def scheduled_start_time - if scheduled_start - scheduled_start.utc.strftime "%a %e %B %Y" + if scheduled_start && scheduled_duration + start_time = scheduled_start + tz_identifier, tz_display = MusicSession.split_timezone(timezone) + begin + tz = TZInfo::Timezone.get(tz_identifier) + rescue Exception => e + @@log.error("unable to find timezone=#{tz_identifier}, e=#{e}") + end + + if tz + begin + start_time = tz.utc_to_local(scheduled_start.utc) + rescue Exception => e + @@log.error("unable to convert #{scheduled_start} to #{tz}, e=#{e}") + puts "unable to convert #{e}" + end + end + + start_time else "" end diff --git a/web/app/assets/javascripts/accounts_session_properties.js b/web/app/assets/javascripts/accounts_session_properties.js index 916188756..878748c35 100644 --- a/web/app/assets/javascripts/accounts_session_properties.js +++ b/web/app/assets/javascripts/accounts_session_properties.js @@ -23,6 +23,7 @@ var $musicNotations = null; var $btnSelectFiles = null; var $uploadSpinner = null; + var $dateTimeTBD = null; var ONE_HOUR = 3600 * 1000; var ONE_MINUTE = 60 * 1000; @@ -44,9 +45,25 @@ function afterShow(data) { } + function toggleDateTBD(e) { + var status = $(e.target)[0].checked; + var $dateField = $screen.find('#session-prop-start-date'); + if (status) { + $dateField.datepicker("disable"); + } + else { + $dateField.datepicker("enable"); + if ($dateField.val() == "") { + $dateField.val(new Date().toDateString()); + } + toggleDate(); + } + } + function events() { $startTimeList.on('change', toggleStartTime); $btnSelectFiles.on('click', toggleSelectFiles); + $dateTimeTBD.on('ifChanged', toggleDateTBD); $screen.find("#session-update").on('click', updateSessionProperties); $screen.find('#session-prop-select-files').on('change', changeSelectedFiles); } @@ -93,7 +110,13 @@ } function toggleDate() { - var selectedDate = new Date($screen.find('#session-prop-start-date').val()); + var selectedDate = null; + if ($screen.find("#session-prop-start-date").val() == "") { + selectedDate = new Date(); + } + else { + selectedDate = new Date($screen.find('#session-prop-start-date').val()); + } var currentDate = new Date(); var startIndex = 0; @@ -189,15 +212,21 @@ } data.legal_policy = $screen.find('#session-policy').val(); data.language = $languageList.val(); - data.start = $screen.find('#session-prop-start-date').val() + ' ' + $startTimeList.val(); - var endDate = new Date($screen.find('#session-prop-start-date').val() + ' ' + $endTimeList.val()); - data.duration = (endDate - new Date(data.start)) / ONE_MINUTE; - if ($endTimeList.val() == defaultTimeArray[0]) { - data.duration += ONE_DAY / ONE_MINUTE; + if ($dateTimeTBD[0].checked) { + data.start = null; + } + else { + data.start = $screen.find('#session-prop-start-date').val() + ' ' + $startTimeList.val(); + var endDate = new Date($screen.find('#session-prop-start-date').val() + ' ' + $endTimeList.val()); + data.duration = (endDate - new Date(data.start)) / ONE_MINUTE; + if ($endTimeList.val() == defaultTimeArray[0]) { + data.duration += ONE_DAY / ONE_MINUTE; + } } data.recurring_mode = $recurringModeList.val(); data.music_notations = sessionData.music_notations; data.timezone = $timezoneList.val(); + data.open_rsvps = $screen.find("#open-rsvp")[0].checked; rest.updateScheduledSession(sessionData.id, data) .done(function(response) { @@ -214,6 +243,12 @@ } ); + $screen.find(".icheckbuttons input").iCheck({ + checkboxClass: 'icheckbox_minimal', + radioClass: 'iradio_minimal', + inheritClass: true + }); + context.JK.GenreSelectorHelper.render('#session-prop-genre'); context.JK.dropdown($musicianAccess); @@ -318,7 +353,14 @@ function renderSession(data) { sessionData = data; - $screen.find('#session-prop-start-date').val(sessionData.scheduled_start_time); + if (sessionData.scheduled_start == null) { + $screen.find("#session-prop-start-date").datepicker("disable"); + $dateTimeTBD.iCheck('check').attr('checked', true); + } + else { + $screen.find('#session-prop-start-date').val(sessionData.scheduled_start_date); + $dateTimeTBD.iCheck('uncheck').attr('checked', false); + } toggleDate(); var startTime = getFormattedTime(new Date(sessionData.scheduled_start), false); @@ -327,12 +369,23 @@ $startTimeList.val(startTime); toggleStartTime(); $endTimeList.val(endTime); - $timezoneList.val(sessionData.timezone); + if (sessionData.timezone == null) { + context.JK.SessionUtils.defaultTimezone($timezoneList); + } + else { + $timezoneList.val(sessionData.timezone); + } $recurringModeList.val(sessionData.recurring_mode); context.JK.GenreSelectorHelper.setSelectedGenres('#session-prop-genre', sessionData.genres); $sessionName.val(sessionData.name); $sessionDescription.val(sessionData.description); $languageList.val(sessionData.language); + if (sessionData.open_rsvps) { + $screen.find("#open-rsvp").iCheck("check").attr("checked", true); + } + else { + $screen.find("#open-rsvp").iCheck("uncheck").attr("checked", false); + } sessionData.musician_access_value = 'musicians'; if (sessionData.musician_access == true && sessionData.approval_required == true) @@ -380,6 +433,7 @@ $musicNotations = $screen.find("#selected-filenames"); $btnSelectFiles = $screen.find("#select-notation-files"); $uploadSpinner = $screen.find(".upload-spinner"); + $dateTimeTBD = $screen.find("#date_time_tbd"); initializeControls(); events(); diff --git a/web/app/assets/javascripts/scheduled_session.js b/web/app/assets/javascripts/scheduled_session.js index 54d08a284..e4c03e0b5 100644 --- a/web/app/assets/javascripts/scheduled_session.js +++ b/web/app/assets/javascripts/scheduled_session.js @@ -359,7 +359,7 @@ } var currentTime = new Date(); - var startTime = new Date(session.scheduled_start_time); + var startTime = new Date(session.scheduled_start); var diffTime = startTime.getTime() - currentTime.getTime(); if (diffTime > ONE_HOUR) { var confirmDialog = new context.JK.ConfirmDialog(app, "Start Session Now", diff --git a/web/app/assets/stylesheets/client/account.css.scss b/web/app/assets/stylesheets/client/account.css.scss index a24d1c05a..f80ef3f02 100644 --- a/web/app/assets/stylesheets/client/account.css.scss +++ b/web/app/assets/stylesheets/client/account.css.scss @@ -350,16 +350,54 @@ line-height: 30px; vertical-align: middle; text-align: right; + margin-top: 5px; } .right-column { - width: 65%; + width: 60%; + margin-left: 5px; + margin-top: 5px; display: inline-block; float: left; line-height: 30px; vertical-align: middle; } + .right-column input[type="text"] { + margin-bottom: 10px; + } + + .right-column input[type="text"], .right-column textarea { + width: 99%; + } + + .right-no-left { + width: 65%; + margin-left: 35%; + display: inline-block; + float: left; + line-height: 30px; + vertical-align: middle; + } + + .open-rsvp-check, .datetime_tbd_check { + float: left; + margin-left: 5px; + } + + .datetime_tbd_label { + float: left; + margin-left: 5px; + } + + .open-rsvp-label { + float: left; + margin: 5px; + width: 85%; + line-height: 19px; + font-weight: 300; + } + .action-bar { margin-top: 20px; } diff --git a/web/app/helpers/music_session_helper.rb b/web/app/helpers/music_session_helper.rb index e556b01c5..b550e70f3 100644 --- a/web/app/helpers/music_session_helper.rb +++ b/web/app/helpers/music_session_helper.rb @@ -63,8 +63,8 @@ module MusicSessionHelper end - def scheduled_start_time(music_session) - music_session.scheduled_start_time + def scheduled_start_date(music_session) + music_session.scheduled_start_date end def pretty_scheduled_start(music_session, with_timezone) diff --git a/web/app/views/api_music_sessions/show_history.rabl b/web/app/views/api_music_sessions/show_history.rabl index 1b7f27652..9d9d42bca 100644 --- a/web/app/views/api_music_sessions/show_history.rabl +++ b/web/app/views/api_music_sessions/show_history.rabl @@ -18,7 +18,7 @@ else attributes :id, :music_session_id, :name, :description, :musician_access, :approval_required, :fan_access, :fan_chat, :band_id, :user_id, :genre_id, :created_at, :like_count, :comment_count, :play_count, :scheduled_duration, - :language, :recurring_mode, :language_description, :scheduled_start_time, :access_description, :timezone, :timezone_id, :timezone_description, + :language, :recurring_mode, :language_description, :scheduled_start_date, :access_description, :timezone, :timezone_id, :timezone_description, :musician_access_description, :fan_access_description, :session_removed_at, :legal_policy, :open_rsvps, :is_unstructured_rsvp? node :share_url do |history| @@ -31,12 +31,12 @@ else [item.genre.description] # XXX: need to return single genre; not array end - node :scheduled_start_time do |session| - scheduled_start_time(session) + node :scheduled_start_date do |session| + scheduled_start_date(session) end node :scheduled_start do |history| - history.scheduled_start.utc.strftime("%a %e %B %Y %H:%M:%S") if history.scheduled_start + history.scheduled_start_time.strftime("%a %e %B %Y %H:%M:%S") if history.scheduled_start end node :pretty_scheduled_start_with_timezone do |session| diff --git a/web/app/views/clients/_account_session_properties.html.haml b/web/app/views/clients/_account_session_properties.html.haml index 95345e58b..16d59f872 100644 --- a/web/app/views/clients/_account_session_properties.html.haml +++ b/web/app/views/clients/_account_session_properties.html.haml @@ -12,12 +12,17 @@ .content-wrapper.account-session-properties #account-session-properties-div .left-panel - .right-column{style: "margin-left: 35%;"} + .right-no-left %strong{style: "font-weight: bold;"} Date & Time .clearall.left-column Date: .right-column %input#session-prop-start-date{type: "text"} + .clearall.right-no-left + .icheckbuttons.datetime_tbd_check + %input{type: "checkbox", id: "date_time_tbd"} + %label.datetime_tbd_label{for: "date_time_tbd"}Date and time TBD + .clearall .clearall.left-column Start: .right-column @@ -40,7 +45,7 @@ %option.label{value: "weekly"} Weekly .clearall .right-panel - .right-column{style: "margin-left: 35%;"} + .right-no-left %strong{style: "font-weight: bold;"} Other Properties .clearall.left-column Genre: @@ -78,6 +83,11 @@ %option{value: "listen-chat-band"} Fans may listen, chat with the band %option{value: "listen-chat-each", selected: "selected"} Fans may listen, chat with each other %option{value: "no-listen-chat"} Fans may not listen to session + .clearall.right-no-left + .icheckbuttons.open-rsvp-check + %input{type: "checkbox", id: "open-rsvp"} + %label.open-rsvp-label{for: "open-rsvp"} Allow interested JamKazam musicians to request a RSVP + .clearall .clearall.left-column Legal: .right-column @@ -101,7 +111,7 @@ .clearall .action-bar .left - %a.button-orange{href: "#", target: "_blank"} HELP + %a.button-grey{href: "#", target: "_blank"} HELP .right %a.button-grey{href: "javascript:history.go(-1)"} CANCEL %a.button-orange{href: "#", id: "session-update"} UPDATE PROPERTIES diff --git a/web/spec/features/account_spec.rb b/web/spec/features/account_spec.rb index a168b6c14..593d5abc2 100644 --- a/web/spec/features/account_spec.rb +++ b/web/spec/features/account_spec.rb @@ -12,7 +12,7 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do sign_in_poltergeist user visit "/client#/account" - find('div.account-mid.identity') + # find('div.account-mid.identity') end it { should have_selector('h1', text: 'my account') } @@ -143,7 +143,6 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do end it "should update scheduled session" do - pending "working on it" find("a.session-detail-button").trigger(:click) find('a.button-orange.update-session', text: "UPDATE").trigger(:click) @@ -151,17 +150,59 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do find('strong', text: "Other Properties") find('#session-prop-name').value.should eq @name + + # update session properties with new values + date = Time.now.strftime "%a %e %B %Y" + fill_in('session-prop-start-date', with: date) + find('a.ui-state-default', text: '11').trigger(:click) + jk_select('11:30 PM', '#account-session-properties-div #start-time-prop-list') + jk_select('12:00 AM', '#account-session-properties-div #end-time-prop-list') + jk_select('(GMT+00:00) UTC', '#account-session-properties-div #timezone-prop-list') + jk_select('African', '#account-session-properties-div select[name="genres"]') fill_in('session-prop-name', with: "Updated Name") + fill_in('session-prop-desc', with: "Updated Description") + jk_select('German', '#account-session-properties-div #session-prop-lang-list') + jk_select('Only RSVP musicians may join', '#account-session-properties-div #session-prop-musician-access') + jk_select('Fans may not listen to session', '#account-session-properties-div #session-prop-fans-access') find('a#session-update').trigger(:click) should have_selector('h2', text: 'Session is successfully updated.') - find('a.button-grey', text: "CANCEL").trigger(:click) + find('a.button-orange', text: "OKAY").trigger(:click) - find('#session-prop-name').value.should eq "Updated Name" + # check updated properties + current_date = Time.now + date_value = Time.new(current_date.year, current_date.mon, 11) + date_string = date_value.strftime "%a %e %B %Y" - find('a.button-grey', text: "CANCEL").trigger(:click) + find('#account-session-properties-div #session-prop-start-date').value.should eq date_string + find('#account-session-properties-div .selected', text: '11:30 PM') + find('#account-session-properties-div .selected', text: '12:00 AM') + find('#account-session-properties-div .selected', text: '(GMT+00:00) UTC') + find('#account-session-properties-div #session-prop-genre .selected', text: 'African') + find('#account-session-properties-div #session-prop-name').value.should eq "Updated Name" + find('#account-session-properties-div #session-prop-desc').value.should eq "Updated Description" + find('#account-session-properties-div .selected', text: 'German') + find('#account-session-properties-div .selected', text: 'Only RSVP musicians may join') + find('#account-session-properties-div .selected', text: 'Fans may not listen to session') + + # try to update without changing the fields + find('a#session-update').trigger(:click) + + should have_selector('h2', text: 'Session is successfully updated.') + find('a.button-orange', text: "OKAY").trigger(:click) + + # check fields with original values + find('#account-session-properties-div #session-prop-start-date').value.should eq date_string + find('#account-session-properties-div .selected', text: '11:30 PM') + find('#account-session-properties-div .selected', text: '12:00 AM') + find('#account-session-properties-div .selected', text: '(GMT+00:00) UTC') + find('#account-session-properties-div #session-prop-genre .selected', text: 'African') + find('#account-session-properties-div #session-prop-name').value.should eq "Updated Name" + find('#account-session-properties-div #session-prop-desc').value.should eq "Updated Description" + find('#account-session-properties-div .selected', text: 'German') + find('#account-session-properties-div .selected', text: 'Only RSVP musicians may join') + find('#account-session-properties-div .selected', text: 'Fans may not listen to session') - find('.session-properties-right', text: "Updated Name") end it "cancel a scheduled sessions" do