Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
[#402](https://github.com/nextcloud/cookbook/pull/402/) @seyfeb
- Allow checking of ingredients in web UI
[#393](https://github.com/nextcloud/cookbook/pull/393) @christianlupus
- Support for dateCreated and dateModified field of schema.org Recipe
[#377](https://github.com/nextcloud/cookbook/pull/366/) @seyfeb

### Changed
- Switch of project ownership to neextcloud organization in GitHub
Expand Down
4 changes: 3 additions & 1 deletion l10n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ OC.L10N.register(
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
"Source" : "Quelle"
"Source" : "Quelle",
"Date created" : "Erzeugt am",
"Last modified" : "Zuletzt geändert"
},
"nplurals=2; plural=(n != 1);");
4 changes: 3 additions & 1 deletion l10n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
"Source" : "Quelle"
"Source" : "Quelle",
"Date created" : "Erzeugt am",
"Last modified" : "Zuletzt geändert"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
4 changes: 3 additions & 1 deletion l10n/de_DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ OC.L10N.register(
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
"Source" : "Quelle"
"Source" : "Quelle",
"Date created" : "Erzeugt am",
"Last modified" : "Zuletzt geändert"
},
"nplurals=2; plural=(n != 1);");
6 changes: 4 additions & 2 deletions l10n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
"Source" : "Quelle"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
"Source" : "Quelle",
"Date created" : "Erzeugt am",
"Last modified" : "Zuletzt geändert"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
4 changes: 3 additions & 1 deletion l10n/en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ OC.L10N.register(
"Loading recipe failed" : "Loading recipe failed",
"Recipe could not be saved" : "Recipe could not be saved",
"Cooking time is up!" : "Cooking time is up!",
"Source" : "Source"
"Source" : "Source",
"Date created" : "Date created",
"Last modified" : "Last modified"
},
"nplurals=2; plural=(n != 1);");
6 changes: 4 additions & 2 deletions l10n/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Loading recipe failed" : "Loading recipe failed",
"Recipe could not be saved" : "Recipe could not be saved",
"Cooking time is up!" : "Cooking time is up!",
"Source" : "Source"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
"Source" : "Source",
"Date created" : "Date created",
"Last modified" : "Last modified"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
15 changes: 12 additions & 3 deletions lib/Service/RecipeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,14 @@ public function addRecipe($json) {
throw new Exception('Recipe name not found');
}

$now = date(DATE_ISO8601);

// Sanity check
$json = $this->checkRecipe($json);

// Update modification date
$json['dateModified'] = $now;

// Create/move recipe folder
$user_folder = $this->getFolderForUser();
$recipe_folder = null;
Expand All @@ -682,6 +687,8 @@ public function addRecipe($json) {

// This is a new recipe, create it
} else {
$json['dateCreated'] = $now;

if ($user_folder->nodeExists($json['name'])) {
throw new Exception('Another recipe with that name already exists');
}
Expand Down Expand Up @@ -1041,11 +1048,13 @@ public function parseRecipeFile($file) {

$json['id'] = $file->getParent()->getId();

if (method_exists($file, 'getCreationTime')) {

if (!array_key_exists('dateCreated', $json) && method_exists($file, 'getCreationTime')) {
$json['dateCreated'] = $file->getCreationTime();
}

$json['dateModified'] = $file->getMTime();
if (!array_key_exists('dateModified', $json)) {
$json['dateModified'] = $file->getMTime();
}

return $this->checkRecipe($json);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"homepage": "https://github.com/mrzapp/nextcloud-cookbook#readme",
"dependencies": {
"@nextcloud/event-bus": "^1.1.4",
"@nextcloud/moment": "^1.1.1",
"@nextcloud/vue": "^1.5.0",
"lozad": "^1.16.0",
"vue": "^2.6.11",
Expand Down
77 changes: 74 additions & 3 deletions src/components/RecipeView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div class="wrapper">

<div v-if="$store.state.recipe" class='header' :class="{ 'responsive': $store.state.recipe.image }">
<div class='image' v-if="$store.state.recipe.image">
<RecipeImages />
Expand All @@ -14,6 +13,16 @@
<ul v-if="keywords.length">
<RecipeKeyword v-for="(keyword,idx) in keywords" :key="'keyw'+idx" :keyword="keyword" v-on:keyword-clicked="keywordClicked(keyword)" />
</ul>
</p>
<p class="dates">
<span v-if="showCreatedDate" class="date" :title="t('cookbook', 'Date created')">
<span class="icon-calendar-dark date-icon" />
<span class="date-text">{{ dateCreated }}</span>
</span>
<span v-if="showModifiedDate" class="date" :title="t('cookbook', 'Last modified')">
<span class="icon-rename date-icon" />
<span class="date-text">{{ dateModified }}</span>
</span>
</p>
<p class="description">{{ $store.state.recipe.description }}</p>
<p v-if="$store.state.recipe.url">
Expand Down Expand Up @@ -59,6 +68,8 @@

<script>

import moment from '@nextcloud/moment'

import RecipeImages from './RecipeImages'
import RecipeIngredient from './RecipeIngredient'
import RecipeInstruction from './RecipeInstruction'
Expand Down Expand Up @@ -86,17 +97,50 @@ export default {
timerPrep: null,
timerTotal: null,
tools: [],
dateCreated: null,
dateModified: null,
}
},
computed: {
showModifiedDate: function() {
if (!this.dateModified) {
return false
}
else if ( this.$store.state.recipe.dateCreated
&& this.$store.state.recipe.dateModified
&& this.$store.state.recipe.dateCreated === this.$store.state.recipe.dateModified) {
// don't show modified date if create and modified timestamp are the same
return false
}
return true
},
showCreatedDate: function() {
if (!this.dateCreated) {
return false
}
return true
},
},
methods: {
/**
* Callback for click on keyword
*/
keywordClicked: function(keyword) {
if(keyword) {
this.$router.push('/tags/'+keyword);
this.$router.push('/tags/'+keyword)
}
},
/* The schema.org standard requires the dates formatted as Date (https://schema.org/Date)
* or DateTime (https://schema.org/DateTime). This follows the ISO 8601 standard.
*/
parseDateTime: function(dt) {
if (!dt) return null
var date = moment(dt, moment.ISO_8601)
if(!date.isValid()) {
return null
}
return date
},
setup: function() {
// Make the control row show that a recipe is loading
if (!this.$store.state.recipe) {
Expand Down Expand Up @@ -133,7 +177,7 @@ export default {
}

if ($this.$store.state.recipe.keywords) {
$this.keywords = String($this.$store.state.recipe.keywords).split(',');
$this.keywords = String($this.$store.state.recipe.keywords).split(',')
}

if ($this.$store.state.recipe.cookTime) {
Expand All @@ -155,6 +199,16 @@ export default {
$this.tools = $this.$store.state.recipe.tool
}

if ($this.$store.state.recipe.dateCreated) {
let date = $this.parseDateTime($this.$store.state.recipe.dateCreated)
$this.dateCreated = (date != null ? date.format('L, LT').toString() : null)
}

if ($this.$store.state.recipe.dateModified) {
let date = $this.parseDateTime($this.$store.state.recipe.dateModified)
$this.dateModified = (date != null ? date.format('L, LT').toString() : null)
}

// Always set the active page last!
$this.$store.dispatch('setPage', { page: 'recipe' })

Expand Down Expand Up @@ -205,6 +259,7 @@ export default {

<style scoped>


.wrapper {
width: 100%;
}
Expand Down Expand Up @@ -243,6 +298,22 @@ aside {
width: 100%;
} }

.dates {
font-size: .9em;
}
.date {
margin-right: 1.5em;
}
.date-icon {
display: inline-block;
background-size: 1em;
margin-right: .2em;
vertical-align: middle;
margin-bottom: .2em;
}
.date-text {
vertical-align: middle;
}
.description {
font-style: italic;
white-space: pre-line;
Expand Down