-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-store-timezone' into develop
Conflicts: db/schema.rb Also added links to visualise projects and sites.
- Loading branch information
Showing
23 changed files
with
226 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
%li.span6 | ||
= link_to project , class: 'thumbnail right-caption span12 project_thumbnail' do | ||
.thumbnail.right-caption.span12.project_thumbnail | ||
.span4= image_tag project.image.url(:span2) | ||
.caption.span7 | ||
%h4= project.name | ||
%h4= link_to project.name, project | ||
%p= truncate(project.description, length: 50, separator: ' ') | ||
- if current_user.can_write?(project) | ||
%i.fa.fa-unlock(title="You have read & write access" data-toggle='tooltip' data-placement='top') | ||
%i.project_permission_icon.fa.fa-unlock(title="You have read & write access" data-toggle='tooltip' data-placement='top') | ||
- elsif current_user.can_read?(project) | ||
%i.fa.fa-lock(title="You have read only access" data-toggle='tooltip' data-placement='top') | ||
%i.project_permission_icon.fa.fa-lock(title="You have read only access" data-toggle='tooltip' data-placement='top') | ||
%ul.nav.nav-pills.nav-stacked.pull-right{style: 'margin-bottom:0'} | ||
%li | ||
%a{href: "/visualize?projectId=#{project.id}"} | ||
%i.fa.fa-eye | ||
Visualise |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
- control_id = "#{model_name}_#{attribute_name}" | ||
- span_id = "#{control_id}_appended_info" | ||
- help_id = "#{control_id}_appended_help" | ||
.control-group.string.optional{class: control_id } | ||
= f.label attribute_name, 'Time Zone', class: 'string optional control-label', for: control_id | ||
.controls | ||
.input-append | ||
= f.input_field attribute_name, type: 'text', autocomplete: 'off', class: 'span12' | ||
%span.add-on{id: span_id, title: 'Time zone abbreviation and current UTC offset'} | ||
(no match) | ||
%p.help-block{id: help_id } | ||
|
||
:javascript | ||
var mapping = #{TimeZoneHelper.mapping_zone_to_offset.to_json} | ||
var mapping_keys = Object.keys(mapping); | ||
var mapping_values = Object.keys(mapping).map(function (key) { return mapping[key]; }); | ||
|
||
$('##{control_id}').typeahead({ | ||
'source': Object.keys(mapping), | ||
'minLength': 2, | ||
'items': 10 | ||
}); | ||
|
||
$('##{control_id}').on('change keydown keypress', function(){ | ||
checkTimeZone(); | ||
}); | ||
|
||
function checkTimeZone(){ | ||
var enteredValue = $('##{control_id}').val(); | ||
var mappingValue = mapping[enteredValue]; | ||
|
||
var appendedInfo = $('##{span_id}'); | ||
var helpInfo = $('##{help_id}'); | ||
if(mappingValue){ | ||
appendedInfo.text(mappingValue); | ||
|
||
var momentTimezoneName = enteredValue; | ||
|
||
// to make this match with moment js | ||
// replace dashes with slashes | ||
var momentTimezoneName = momentTimezoneName.replace(' - ', '/'); | ||
var momentTimezoneName = momentTimezoneName.replace("'", ''); | ||
|
||
// move place name after comma | ||
var commaIndex = momentTimezoneName.indexOf(', '); | ||
if (commaIndex >= 0){ | ||
var toMove = momentTimezoneName.substring(commaIndex + 2); | ||
momentTimezoneName = momentTimezoneName.replace('/', '/' + toMove + '/'); | ||
momentTimezoneName = momentTimezoneName.substring(0,momentTimezoneName.indexOf(', ')); | ||
} | ||
|
||
// replace spaces with underscores | ||
var momentTimezoneName = momentTimezoneName.replace(' ', '_'); | ||
|
||
var origTime = moment().tz(momentTimezoneName); | ||
var formatted = origTime.format("dddd, MMMM Do YYYY, h:mm:ss a z Z") | ||
helpInfo.text('Currently: ' + formatted); | ||
} else { | ||
appendedInfo.text('(no match)'); | ||
helpInfo.text('(no match)'); | ||
} | ||
} | ||
|
||
// check time zone when page loads | ||
$(document).ready(function() { | ||
checkTimeZone(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
%li.span12 | ||
= link_to [@project, site] , class: 'thumbnail right-caption span12' do | ||
.thumbnail.right-caption.span12 | ||
= image_tag site.image.url(:span1) | ||
.caption | ||
%h3= site.name | ||
%h3= link_to site.name, [@project, site] | ||
%ul.nav.nav-pills.nav-stacked.pull-right{style: 'margin-bottom:0'} | ||
%li | ||
%a{href: "/visualize?siteId=#{site.id}"} | ||
%i.fa.fa-eye | ||
Visualise | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddTimezoneColumns < ActiveRecord::Migration | ||
def change | ||
add_column :users, :tzinfo_tz, :string, null: true, limit: 255 | ||
add_column :users, :rails_tz, :string, null: true, limit: 255 | ||
|
||
add_column :sites, :tzinfo_tz, :string, null: true, limit: 255 | ||
add_column :sites, :rails_tz, :string, null: true, limit: 255 | ||
|
||
add_column :audio_recordings, :recorded_utc_offset, :string, null: true, limit: 20 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require 'tzinfo' | ||
require 'active_support' | ||
|
||
class TimeZoneHelper | ||
class << self | ||
def mapping_zone_to_offset | ||
Hash[ | ||
TZInfo::Timezone.all.map do |tz| | ||
this_tz = TZInfo::Timezone.get(tz.identifier) | ||
period = this_tz.current_period | ||
abbr = period.abbreviation | ||
offset = period.utc_total_offset # in seconds | ||
offset_hours = offset / (60 * 60) | ||
offset_minutes = (offset % 60).to_s.rjust(2, '0') | ||
|
||
if offset_hours < 0 | ||
offset_hours = (offset_hours * -1).to_s.rjust(2, '0') | ||
offset_hours = '-' + offset_hours | ||
else | ||
offset_hours = '+'+ offset_hours.to_s.rjust(2, '0') | ||
end | ||
|
||
[ | ||
tz.to_s, | ||
"#{abbr} (#{offset_hours}:#{offset_minutes})" | ||
] | ||
end | ||
] | ||
end | ||
|
||
def to_identifier(friendly_name) | ||
found = TZInfo::Timezone.all.select { |tz| friendly_name == tz.friendly_identifier} | ||
if found.size == 1 | ||
found[0].identifier | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def to_friendly(identifier) | ||
found = TZInfo::Timezone.all.select { |tz| identifier == tz.identifier} | ||
if found.size == 1 | ||
found[0].friendly_identifier | ||
else | ||
nil | ||
end | ||
end | ||
|
||
# Get the TZInfo Timezone equivalent to the Ruby TimeZone. | ||
# @param [string] ruby_tz_name | ||
# @return [TZInfo::Timezone] TZInfo Timezone | ||
def ruby_to_tzinfo(ruby_tz_name) | ||
TZInfo::Timezone.get(ActiveSupport::TimeZone::MAPPING[ruby_tz_name]) | ||
end | ||
|
||
# Get the Ruby TimeZone equivalent to the TZInfo Timezone. | ||
# @param [string] tzinfo_tz_name | ||
# @return [string] Ruby Timezone | ||
def tzinfo_to_ruby(tzinfo_tz_name) | ||
ActiveSupport::TimeZone::MAPPING.invert[tzinfo_tz_name] | ||
end | ||
|
||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.