@@ -34,17 +39,34 @@
computed: {
...mapState({
recipeId: state => state.route.params.id,
+ routeQuery: state => state.route.query,
scale: state => state.route.query.scale || null,
system: state => state.route.query.system || null,
unit: state => state.route.query.unit || null
- })
+ }),
+
+ isScaled() {
+ return this.recipe.converted_scale !== null && this.recipe.converted_scale.length > 0 && this.recipe.converted_scale !== "1";
+ }
+ },
+
+ watch: {
+ routeQuery() {
+ this.refreshData();
+ }
+ },
+
+ methods: {
+ refreshData() {
+ this.loadResource(
+ api.getRecipe(this.recipeId, this.scale, this.system, this.unit)
+ .then(data => { this.recipe = data; return data; })
+ );
+ }
},
created() {
- this.loadResource(
- api.getRecipe(this.recipeId, this.scale, this.system, this.unit)
- .then(data => { this.recipe = data; return data; })
- );
+ this.refreshData();
},
components: {
diff --git a/app/javascript/lib/GlobalMixins.js b/app/javascript/lib/GlobalMixins.js
index 1c1ef95..699be15 100644
--- a/app/javascript/lib/GlobalMixins.js
+++ b/app/javascript/lib/GlobalMixins.js
@@ -27,4 +27,37 @@ Vue.mixin({
.then(() => this.setLoading(false));
}
}
+});
+
+function clickStrikeClick(evt) {
+ const isStrikable = el => el && el.tagName === "LI";
+ const strikeClass = "is-strikethrough";
+
+ let t = evt.target;
+
+ while (t !== null && t !== this && !isStrikable(t)) {
+ t = t.parentElement;
+ }
+
+ if (isStrikable(t)) {
+ const classList = t.className.split(" ");
+ const strIdx = classList.findIndex(c => c === strikeClass);
+ if (strIdx >= 0) {
+ classList.splice(strIdx, 1);
+ } else {
+ classList.push(strikeClass);
+ }
+
+ t.className = classList.join(" ");
+ }
+}
+
+Vue.directive('click-strike', {
+ bind(el) {
+ el.addEventListener("click", clickStrikeClick);
+ },
+
+ unbind(el) {
+ el.removeEventListener("click", clickStrikeClick);
+ }
});
\ No newline at end of file
diff --git a/app/javascript/styles/index.scss b/app/javascript/styles/index.scss
index b584b49..133ec82 100644
--- a/app/javascript/styles/index.scss
+++ b/app/javascript/styles/index.scss
@@ -42,3 +42,7 @@ body {
.pagination:not(:last-child) {
margin-bottom: 1em;
}
+
+.is-strikethrough {
+ text-decoration: line-through;
+}
\ No newline at end of file
diff --git a/app/models/recipe.rb b/app/models/recipe.rb
index 5e6aeac..2c83260 100644
--- a/app/models/recipe.rb
+++ b/app/models/recipe.rb
@@ -16,31 +16,38 @@ class Recipe < ApplicationRecord
validates :total_time, numericality: true, allow_blank: true
validates :active_time, numericality: true, allow_blank: true
+ attr_accessor :converted_scale, :converted_system, :converted_unit
+
def scale(factor, auto_unit = false)
+ self.converted_scale = factor
recipe_ingredients.each do |ri|
ri.scale(factor, auto_unit)
end
end
def convert_to_metric
+ self.converted_system = 'metric'
recipe_ingredients.each do |ri|
ri.to_metric
end
end
def convert_to_standard
+ self.converted_system = 'standard'
recipe_ingredients.each do |ri|
ri.to_standard
end
end
def convert_to_mass
+ self.converted_unit = 'mass'
recipe_ingredients.each do |ri|
ri.to_mass
end
end
def convert_to_volume
+ self.converted_unit = 'volume'
recipe_ingredients.each do |ri|
ri.to_volume
end
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index bcd7507..353c127 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -3,6 +3,8 @@
+
+
Parsley
<%= stylesheet_pack_tag 'application' %>
diff --git a/app/views/recipes/_recipe.json.jbuilder b/app/views/recipes/_recipe.json.jbuilder
index 5264a39..317fa21 100644
--- a/app/views/recipes/_recipe.json.jbuilder
+++ b/app/views/recipes/_recipe.json.jbuilder
@@ -1,6 +1,6 @@
-json.extract! recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text
+json.extract! recipe, :id, :name, :rating, :yields, :total_time, :active_time, :created_at, :updated_at, :step_text, :converted_scale, :converted_system, :converted_unit
json.rendered_steps MarkdownProcessor.render(recipe.step_text)
diff --git a/public/manifest.json b/public/manifest.json
new file mode 100644
index 0000000..0709599
--- /dev/null
+++ b/public/manifest.json
@@ -0,0 +1,8 @@
+{
+ "name": "Parsley",
+ "short_name": "Parsley",
+ "start_url": ".",
+ "display": "standalone",
+ "background_color": "#4a4a4a",
+ "description": "A simply readable Hacker News app."
+}
\ No newline at end of file