Skip to content

Commit f9bfc95

Browse files
Merge pull request #377 from seyfeb/feature/addDateCreated
Support dateCreated and dateModified fields
2 parents 7c89ba9 + 6392218 commit f9bfc95

File tree

10 files changed

+109
-14
lines changed

10 files changed

+109
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
[#402](https://github.com/nextcloud/cookbook/pull/402/) @seyfeb
3636
- Allow checking of ingredients in web UI
3737
[#393](https://github.com/nextcloud/cookbook/pull/393) @christianlupus
38+
- Support for dateCreated and dateModified field of schema.org Recipe
39+
[#377](https://github.com/nextcloud/cookbook/pull/366/) @seyfeb
3840

3941
### Changed
4042
- Switch of project ownership to neextcloud organization in GitHub

l10n/de.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ OC.L10N.register(
6464
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
6565
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
6666
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
67-
"Source" : "Quelle"
67+
"Source" : "Quelle",
68+
"Date created" : "Erzeugt am",
69+
"Last modified" : "Zuletzt geändert"
6870
},
6971
"nplurals=2; plural=(n != 1);");

l10n/de.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
6363
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
6464
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
65-
"Source" : "Quelle"
65+
"Source" : "Quelle",
66+
"Date created" : "Erzeugt am",
67+
"Last modified" : "Zuletzt geändert"
6668
},"pluralForm" :"nplurals=2; plural=(n != 1);"
6769
}

l10n/de_DE.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ OC.L10N.register(
6464
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
6565
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
6666
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
67-
"Source" : "Quelle"
67+
"Source" : "Quelle",
68+
"Date created" : "Erzeugt am",
69+
"Last modified" : "Zuletzt geändert"
6870
},
6971
"nplurals=2; plural=(n != 1);");

l10n/de_DE.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"Loading recipe failed" : "Laden des Rezepts fehlgeschlagen",
6363
"Recipe could not be saved" : "Rezept konnte nicht gespeichert werden",
6464
"Cooking time is up!" : "Die Kochzeit ist vorbei!",
65-
"Source" : "Quelle"
66-
},"pluralForm" :"nplurals=2; plural=(n != 1);"
65+
"Source" : "Quelle",
66+
"Date created" : "Erzeugt am",
67+
"Last modified" : "Zuletzt geändert"
68+
},"pluralForm" :"nplurals=2; plural=(n != 1);"
6769
}

l10n/en_GB.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ OC.L10N.register(
6464
"Loading recipe failed" : "Loading recipe failed",
6565
"Recipe could not be saved" : "Recipe could not be saved",
6666
"Cooking time is up!" : "Cooking time is up!",
67-
"Source" : "Source"
67+
"Source" : "Source",
68+
"Date created" : "Date created",
69+
"Last modified" : "Last modified"
6870
},
6971
"nplurals=2; plural=(n != 1);");

l10n/en_GB.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"Loading recipe failed" : "Loading recipe failed",
6363
"Recipe could not be saved" : "Recipe could not be saved",
6464
"Cooking time is up!" : "Cooking time is up!",
65-
"Source" : "Source"
66-
},"pluralForm" :"nplurals=2; plural=(n != 1);"
65+
"Source" : "Source",
66+
"Date created" : "Date created",
67+
"Last modified" : "Last modified"
68+
},"pluralForm" :"nplurals=2; plural=(n != 1);"
6769
}

lib/Service/RecipeService.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,14 @@ public function addRecipe($json) {
657657
throw new Exception('Recipe name not found');
658658
}
659659

660+
$now = date(DATE_ISO8601);
661+
660662
// Sanity check
661663
$json = $this->checkRecipe($json);
662664

665+
// Update modification date
666+
$json['dateModified'] = $now;
667+
663668
// Create/move recipe folder
664669
$user_folder = $this->getFolderForUser();
665670
$recipe_folder = null;
@@ -682,6 +687,8 @@ public function addRecipe($json) {
682687

683688
// This is a new recipe, create it
684689
} else {
690+
$json['dateCreated'] = $now;
691+
685692
if ($user_folder->nodeExists($json['name'])) {
686693
throw new Exception('Another recipe with that name already exists');
687694
}
@@ -1041,11 +1048,13 @@ public function parseRecipeFile($file) {
10411048

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

1044-
if (method_exists($file, 'getCreationTime')) {
1051+
1052+
if (!array_key_exists('dateCreated', $json) && method_exists($file, 'getCreationTime')) {
10451053
$json['dateCreated'] = $file->getCreationTime();
10461054
}
1047-
1048-
$json['dateModified'] = $file->getMTime();
1055+
if (!array_key_exists('dateModified', $json)) {
1056+
$json['dateModified'] = $file->getMTime();
1057+
}
10491058

10501059
return $this->checkRecipe($json);
10511060
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"homepage": "https://github.com/mrzapp/nextcloud-cookbook#readme",
2121
"dependencies": {
2222
"@nextcloud/event-bus": "^1.1.4",
23+
"@nextcloud/moment": "^1.1.1",
2324
"@nextcloud/vue": "^1.5.0",
2425
"lozad": "^1.16.0",
2526
"vue": "^2.6.11",

src/components/RecipeView.vue

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<div class="wrapper">
3-
43
<div v-if="$store.state.recipe" class='header' :class="{ 'responsive': $store.state.recipe.image }">
54
<div class='image' v-if="$store.state.recipe.image">
65
<RecipeImages />
@@ -14,6 +13,16 @@
1413
<ul v-if="keywords.length">
1514
<RecipeKeyword v-for="(keyword,idx) in keywords" :key="'keyw'+idx" :keyword="keyword" v-on:keyword-clicked="keywordClicked(keyword)" />
1615
</ul>
16+
</p>
17+
<p class="dates">
18+
<span v-if="showCreatedDate" class="date" :title="t('cookbook', 'Date created')">
19+
<span class="icon-calendar-dark date-icon" />
20+
<span class="date-text">{{ dateCreated }}</span>
21+
</span>
22+
<span v-if="showModifiedDate" class="date" :title="t('cookbook', 'Last modified')">
23+
<span class="icon-rename date-icon" />
24+
<span class="date-text">{{ dateModified }}</span>
25+
</span>
1726
</p>
1827
<p class="description">{{ $store.state.recipe.description }}</p>
1928
<p v-if="$store.state.recipe.url">
@@ -59,6 +68,8 @@
5968

6069
<script>
6170
71+
import moment from '@nextcloud/moment'
72+
6273
import RecipeImages from './RecipeImages'
6374
import RecipeIngredient from './RecipeIngredient'
6475
import RecipeInstruction from './RecipeInstruction'
@@ -86,17 +97,50 @@ export default {
8697
timerPrep: null,
8798
timerTotal: null,
8899
tools: [],
100+
dateCreated: null,
101+
dateModified: null,
89102
}
90103
},
104+
computed: {
105+
showModifiedDate: function() {
106+
if (!this.dateModified) {
107+
return false
108+
}
109+
else if ( this.$store.state.recipe.dateCreated
110+
&& this.$store.state.recipe.dateModified
111+
&& this.$store.state.recipe.dateCreated === this.$store.state.recipe.dateModified) {
112+
// don't show modified date if create and modified timestamp are the same
113+
return false
114+
}
115+
return true
116+
},
117+
showCreatedDate: function() {
118+
if (!this.dateCreated) {
119+
return false
120+
}
121+
return true
122+
},
123+
},
91124
methods: {
92125
/**
93126
* Callback for click on keyword
94127
*/
95128
keywordClicked: function(keyword) {
96129
if(keyword) {
97-
this.$router.push('/tags/'+keyword);
130+
this.$router.push('/tags/'+keyword)
98131
}
99132
},
133+
/* The schema.org standard requires the dates formatted as Date (https://schema.org/Date)
134+
* or DateTime (https://schema.org/DateTime). This follows the ISO 8601 standard.
135+
*/
136+
parseDateTime: function(dt) {
137+
if (!dt) return null
138+
var date = moment(dt, moment.ISO_8601)
139+
if(!date.isValid()) {
140+
return null
141+
}
142+
return date
143+
},
100144
setup: function() {
101145
// Make the control row show that a recipe is loading
102146
if (!this.$store.state.recipe) {
@@ -133,7 +177,7 @@ export default {
133177
}
134178
135179
if ($this.$store.state.recipe.keywords) {
136-
$this.keywords = String($this.$store.state.recipe.keywords).split(',');
180+
$this.keywords = String($this.$store.state.recipe.keywords).split(',')
137181
}
138182
139183
if ($this.$store.state.recipe.cookTime) {
@@ -155,6 +199,16 @@ export default {
155199
$this.tools = $this.$store.state.recipe.tool
156200
}
157201
202+
if ($this.$store.state.recipe.dateCreated) {
203+
let date = $this.parseDateTime($this.$store.state.recipe.dateCreated)
204+
$this.dateCreated = (date != null ? date.format('L, LT').toString() : null)
205+
}
206+
207+
if ($this.$store.state.recipe.dateModified) {
208+
let date = $this.parseDateTime($this.$store.state.recipe.dateModified)
209+
$this.dateModified = (date != null ? date.format('L, LT').toString() : null)
210+
}
211+
158212
// Always set the active page last!
159213
$this.$store.dispatch('setPage', { page: 'recipe' })
160214
@@ -205,6 +259,7 @@ export default {
205259

206260
<style scoped>
207261
262+
208263
.wrapper {
209264
width: 100%;
210265
}
@@ -243,6 +298,22 @@ aside {
243298
width: 100%;
244299
} }
245300
301+
.dates {
302+
font-size: .9em;
303+
}
304+
.date {
305+
margin-right: 1.5em;
306+
}
307+
.date-icon {
308+
display: inline-block;
309+
background-size: 1em;
310+
margin-right: .2em;
311+
vertical-align: middle;
312+
margin-bottom: .2em;
313+
}
314+
.date-text {
315+
vertical-align: middle;
316+
}
246317
.description {
247318
font-style: italic;
248319
white-space: pre-line;

0 commit comments

Comments
 (0)