Skip to content

Commit 9358445

Browse files
author
root
committed
Fixes #10
1 parent c876164 commit 9358445

File tree

6 files changed

+54
-16
lines changed

6 files changed

+54
-16
lines changed

appinfo/info.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<name>Cookbook</name>
66
<summary>An integrated cookbook using schema.org JSON files files as recipes</summary>
77
<description><![CDATA[A library for all your recipes. It uses JSON files following the schema.org recipe format. To add a recipe to the collection, you can paste in the URL of the recipe, and the provided web page will be parsed and downloaded to whichever folder you specify in the app settings.]]></description>
8-
<version>0.1.4</version>
8+
<version>0.1.5</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >Jeppe Zapp</author>
1111
<namespace>Cookbook</namespace>
1212
<category>organization</category>
1313
<bugs>https://github.com/mrzapp/nextcloud-cookbook/issues</bugs>
1414
<dependencies>
15-
<nextcloud min-version="14" max-version="17"/>
15+
<nextcloud min-version="14" max-version="18"/>
1616
</dependencies>
1717
<navigations>
1818
<navigation>

css/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
* Navigation
1010
*/
1111
#app-navigation {}
12+
#app-navigation .app-navigation-create {
13+
padding: 10px;
14+
}
15+
16+
#app-navigation .app-navigation-create .button {
17+
width: 100%;
18+
padding: 6px 12px;
19+
padding-left: 12px;
20+
padding-left: 34px;
21+
margin: 0;
22+
border-radius: var(--border-radius);
23+
background-position: left 9px center;
24+
z-index: 2;
25+
}
26+
1227
#app-navigation .app-navigation-new {
1328
display: flex;
1429
}

js/script.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Cookbook.prototype = {
3131
url: this._baseUrl + '/update',
3232
method: 'POST',
3333
data: json
34-
}).done(function () {
35-
deferred.resolve();
34+
}).done(function (response) {
35+
deferred.resolve(response);
3636
}).fail(function () {
3737
deferred.reject();
3838
});
@@ -125,13 +125,13 @@ var Content = function (cookbook) {
125125
*/
126126
self.render = function () {
127127
var recipeId = cookbook.getActiveId();
128-
var isEditor = location.hash.indexOf('|edit') > -1;
128+
var isEditor = location.hash.indexOf('|edit') > -1 || location.hash === '#new';
129129

130-
if(!recipeId) {
130+
if(!recipeId && !isEditor) {
131131
$('#app-content-wrapper').html('Please pick a recipe');
132132
} else {
133133
$.ajax({
134-
url: cookbook._baseUrl + '/' + (isEditor ? 'edit' : 'recipe') + '?id=' + recipeId,
134+
url: cookbook._baseUrl + '/' + (isEditor ? 'edit' : 'recipe') + (isEditor && !recipeId ? '?new' : '?id=' + recipeId),
135135
method: 'GET',
136136
})
137137
.done(function (html) {
@@ -192,12 +192,13 @@ var Content = function (cookbook) {
192192
var data = $(e.currentTarget).serialize();
193193

194194
cookbook.update(data)
195-
.then(function() {
196-
location.hash = location.hash.replace(/[^0-9]+/g, '');
195+
.then(function(id) {
196+
location.hash = id;
197197

198198
self.render();
199+
nav.render();
199200
})
200-
.catch(function(e) {
201+
.fail(function(e) {
201202
alert('Could not update recipe');
202203

203204
if(e && e instanceof Error) { throw e; }
@@ -221,7 +222,16 @@ var Nav = function (cookbook) {
221222
self.render();
222223
});
223224
};
224-
225+
226+
/**
227+
* Event: Create new recipe
228+
*/
229+
self.onCreateNewRecipe = function(e) {
230+
e.preventDefault();
231+
232+
location.hash = 'new';
233+
}
234+
225235
/**
226236
* Event: Submit new recipe
227237
*/
@@ -313,7 +323,7 @@ var Nav = function (cookbook) {
313323
})
314324
.done(function(html) {
315325
$('#app-navigation #recipes').html(html);
316-
326+
317327
$('#app-navigation #recipes .button-edit button').click(self.onEditRecipe);
318328

319329
$('#app-navigation #recipes .button-delete button').click(self.onDeleteRecipe);
@@ -327,6 +337,10 @@ var Nav = function (cookbook) {
327337
// Change recipe folder
328338
$('#recipe-folder').off('click');
329339
$('#recipe-folder').click(self.onChangeRecipeFolder);
340+
341+
// Create a new recipe
342+
$('#create-recipe').off('submit');
343+
$('#create-recipe').submit(self.onCreateNewRecipe);
330344

331345
// Add a new recipe
332346
$('#add-recipe').off('submit');

lib/Controller/PageController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ public function recipe() {
6969
* @NoCSRFRequired
7070
*/
7171
public function edit() {
72-
if(!isset($_GET['id'])) {
73-
return new DataResponse('Paramater "id" is required', 400);
72+
if(!isset($_GET['id']) && !isset($_GET['new'])) {
73+
return new DataResponse('Paramater "id" or "new" is required', 400);
7474
}
7575

7676
try {
77-
$recipe = $this->service->getRecipeById($_GET['id']);
77+
$recipe = [];
78+
79+
if(isset($_GET['id'])) {
80+
$recipe = $this->service->getRecipeById($_GET['id']);
81+
}
82+
7883
$response = new TemplateResponse('cookbook', 'content/edit', $recipe);
7984
$response->renderAs('blank');
8085

lib/Controller/RecipeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function update() {
111111

112112
$file = $this->service->addRecipe($json);
113113

114-
return new DataResponse($file->getContent(), Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
114+
return new DataResponse($file->getId(), Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
115115
}
116116

117117
/**

templates/navigation/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<form id="create-recipe" class="app-navigation-create">
2+
<button type="submit" title="Create recipe" class="button icon-add">Create recipe</button>
3+
</form>
4+
15
<form id="add-recipe" class="app-navigation-new">
26
<input name="url" placeholder="Recipe URL">
37
<button type="submit" title="Download recipe">

0 commit comments

Comments
 (0)