Skip to content

Commit

Permalink
Merge branch 'gregschmit:master' into fix-images
Browse files Browse the repository at this point in the history
  • Loading branch information
davegudge authored Aug 27, 2024
2 parents 59cb901 + 5dd3177 commit efae445
Show file tree
Hide file tree
Showing 31 changed files with 788 additions and 598 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test

on: [ push, pull_request ]

jobs:
test:
name: ${{matrix.ruby}}, ${{matrix.gemfile}}
runs-on: ubuntu-latest

strategy:
matrix:
ruby: [ '3.0', '3.1', '3.2', '3.3' ]
gemfile:
- Gemfile
- spec/gemfiles/rails-6.1
- spec/gemfiles/rails-7.0

env:
BUNDLE_GEMFILE: ${{matrix.gemfile}}

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true # 'bundle install' and cache
- run: bundle exec rspec --format documentation
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.gem
spec/gemfiles/Gemfile*.lock
Gemfile.lock
spec/gemfiles/*.lock
*Gemfile.lock
*.gem

.bundle/
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.7
3.0.6
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 4.0.0 / upcoming

* [BREAKING-CHANGE] Drop support for Rails < 6.1
* [BREAKING-CHANGE] Drop support for Ruby < 3.0
* [BREAKING-CHANGE] Convert to vanilla js, remove coffeescript dependency
* [BREAKING-CHANGE] Remove jquery dependency
* [FIX] Fix event handling when switching between frequencies
* remove databse dependency from dummy app
* move CI from Travis to GitHub

# 2.0.0 / 2015-09-24

* [BREAKING-CHANGE] Dropping support for rails 3.X - Upgrade to sass-rails 4
Expand Down
10 changes: 3 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
source 'https://rubygems.org'
source "https://rubygems.org"
gemspec

gem "pg"

gem "jquery-rails"

gem "rails", "~> 5.2"
gem "sass-rails", "~> 5.0"
gem "thin"
gem "rails", "~> 7.1.1"
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ gem 'recurring_select'
- application.css: `//= require recurring_select`

#### jQuery Mobile Interface:
- application.js: `//= require jquery`
- application.js: `//= require jquery-mobile-rs`
- application.css: `//= require jquery-mobile-rs`

Expand Down Expand Up @@ -99,8 +100,8 @@ You have to translate JavaScript texts too by including the locale file in your

For other languages include a JavaScript file like this:

```coffeescript
$.fn.recurring_select.texts = {
```js
RecurringSelectDialog.config.texts = {
locale_iso_code: "fr"
repeat: "Repeat"
frequency: "Frequency"
Expand All @@ -125,8 +126,8 @@ $.fn.recurring_select.texts = {

Options include:

```coffeescript
$.fn.recurring_select.options = {
```js
RecurringSelectDialog.config.options = {
monthly: {
show_week: [true, true, true, true, false, false] //display week 1, 2 .... Last
}
Expand All @@ -135,13 +136,6 @@ $.fn.recurring_select.options = {

## Testing and Development

The dummy app uses a [Postgres](http://postgresapp.com/) database `recurring_select_development`. To get setup:

```console
bundle
rake db:create
```

Start the dummy server for clicking around the interface:

```console
Expand All @@ -151,8 +145,8 @@ rails s
Tests can be ran against different versions of Rails like so:

```
BUNDLE_GEMFILE=spec/gemfiles/Gemfile.rails-4.0.x bundle install
BUNDLE_GEMFILE=spec/gemfiles/Gemfile.rails-4.0.x bundle exec rspec spec
BUNDLE_GEMFILE=spec/gemfiles/rails-7 bundle install
BUNDLE_GEMFILE=spec/gemfiles/rails-7 bundle exec rspec spec
```

Feel free to open issues or send pull requests.
Expand Down
31 changes: 31 additions & 0 deletions app/assets/javascripts/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const defaultConfig = {
options: {
monthly: {
show_week: [true, true, true, true, false, false]
}
},
texts: {
locale_iso_code: "en",
repeat: "Repeat",
last_day: "Last Day",
frequency: "Frequency",
daily: "Daily",
weekly: "Weekly",
monthly: "Monthly",
yearly: "Yearly",
every: "Every",
days: "day(s)",
weeks_on: "week(s) on",
months: "month(s)",
years: "year(s)",
day_of_month: "Day of month",
day_of_week: "Day of week",
cancel: "Cancel",
ok: "OK",
summary: "Summary",
first_day_of_week: 0,
days_first_letter: ["S", "M", "T", "W", "T", "F", "S" ],
order: ["1st", "2nd", "3rd", "4th", "5th", "Last"],
show_week: [true, true, true, true, false, false]
}
}
20 changes: 20 additions & 0 deletions app/assets/javascripts/jquery-mobile-rs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//= require recurring_select
//= require_self

const $ = jQuery

$(function() {
$(document).on("recurring_select:cancel recurring_select:save", ".recurring_select", function() {
$(this).selectmenu('refresh');
});

$(document).on("recurring_select:dialog_opened", ".rs_dialog_holder", function() {
$(this).find("select").attr("data-theme", $('.recurring_select').data("theme")).attr("data-mini", true).selectmenu();
$(this).find("input[type=text]").textinput();

$(this).on("recurring_select:dialog_positioned", ".rs_dialog", function() {
$(this).css({
"top" : $(window).scrollTop()+"px"});
});
});
});
15 changes: 0 additions & 15 deletions app/assets/javascripts/jquery-mobile-rs.js.coffee

This file was deleted.

96 changes: 96 additions & 0 deletions app/assets/javascripts/recurring_select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//= require recurring_select_dialog
//= require_self

document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("focusin", (e) => {
if (e.target.matches(".recurring_select")) {
recurring_select.call(e.target, "set_initial_values")
}
})

document.addEventListener("input", (e) => {
if (e.target.matches(".recurring_select")) {
recurring_select.call(e.target, "changed")
}
})
})

const methods = {
set_initial_values() {
const str = this.querySelectorAll('option')[this.selectedIndex].textContent
this.setAttribute('data-initial-value-hash', this.value);
this.setAttribute('data-initial-value-str', str);
},

changed() {
if (this.value == "custom") {
methods.open.call(this);
} else {
methods.set_initial_values.call(this);
}
},

open() {
this.setAttribute("data-recurring-select-active", true);
new RecurringSelectDialog(this);
this.blur();
},

save(new_rule) {
this.querySelectorAll("option[data-custom]").forEach((el) => el.parentNode.removeChild(el) )
const new_json_val = JSON.stringify(new_rule.hash)

// TODO: check for matching name, and replace that value if found

const options = Array.from(this.querySelectorAll("option")).map(() => this.value)
if (!options.includes(new_json_val)) {
methods.insert_option.apply(this, [new_rule.str, new_json_val])
}

this.value = new_json_val
methods.set_initial_values.apply(this)
this.dispatchEvent(new CustomEvent("recurring_select:save"))
},

current_rule() {
return {
str: this.getAttribute("data-initial-value-str"),
hash: JSON.parse(this.getAttribute("data-initial-value-hash"))
};
},

cancel() {
this.value = this.getAttribute("data-initial-value-hash")
this.setAttribute("data-recurring-select-active", false);
this.dispatchEvent(new CustomEvent("recurring_select:cancel"))
},


insert_option(new_rule_str, new_rule_json) {
let separator = this.querySelectorAll("option[disabled]");
if (separator.length === 0) {
separator = this.querySelectorAll("option");
}
separator = separator[separator.length-1]

const new_option = document.createElement("option")
new_option.setAttribute("data-custom", true);

if (new_rule_str.substr(new_rule_str.length - 1) !== "*") {
new_rule_str+="*";
}

new_option.textContent = new_rule_str
new_option.value = new_rule_json
separator.parentNode.insertBefore(new_option, separator)
}
};

function recurring_select(method) {
this['recurring_select'] = this['recurring_select'] || recurring_select.bind(this)
if (method in methods) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) );
} else {
throw new Error( `Method ${method} does not exist on recurring_select` );
}
}
Loading

0 comments on commit efae445

Please sign in to comment.