Skip to content

Commit

Permalink
fixed backend public offers
Browse files Browse the repository at this point in the history
  • Loading branch information
TJTorola committed May 31, 2016
1 parent 4f5a0b6 commit 2217c0d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 22 deletions.
27 changes: 27 additions & 0 deletions app/Http/Controllers/PublicController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App;
use App\Offer;

class PublicController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function offer($id) {
$offer = Offer::findOrFail($id);
if ($offer->public) {
return $offer->toPublicArray();
}
App::abort(404);
}
}
6 changes: 6 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@
});
});

Route::group(['prefix' => 'public-api'], function() {

Route::get('offer/{id}', 'PublicController@offer');

});

/*
|--------------------------------------------------------------------------
| Admin panel
Expand Down
5 changes: 3 additions & 2 deletions app/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static function saveMany($items, $offer_id)
* @var array
*/
protected $casts = [
'infinite' => 'boolean',
'infinite' => 'boolean',
'public' => 'boolean',
'type_info' => 'array',
];

Expand Down Expand Up @@ -160,7 +161,7 @@ public function getFullNewlineNameAttribute()
|--------------------------------------------------------------------------
*/

static public function extractTypeInfo($item)
static public function extractTypeInfo($item)
{
$type = $item['type'];
$schema = config("samwise.type_schema.item.$type");
Expand Down
5 changes: 3 additions & 2 deletions app/Offer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Offer extends Model
*/
protected $casts = [
'type_info' => 'array',
'public' => 'boolean'
];

/*
Expand Down Expand Up @@ -184,7 +185,7 @@ public function getTimestampAttribute()
|--------------------------------------------------------------------------
*/

static public function extractTypeInfo($offer)
static public function extractTypeInfo($offer)
{
$type = $offer['type'];
$schema = config("samwise.type_schema.offer.$type");
Expand Down Expand Up @@ -260,7 +261,7 @@ public function toPublicArray()
* Set mapping properties
*/


protected $mappingProperties = array(
'tag_array' => [
'type' => 'string',
Expand Down
24 changes: 16 additions & 8 deletions app/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ static public function index()
Offer::putMapping($ignoreConflicts = true);
$offer_chunks = Offer::all()->chunk(50);
foreach ($offer_chunks as $offers) {
$offers->addToIndex();
foreach ($offers as $offer ) {
if ($offer->public) {
$offer->addToIndex();
}
}
}

// Item index
// Item::putMapping($ignoreConflicts = true);
$item_chunks = Item::all()->chunk(50);
foreach ($item_chunks as $items) {
$items->addToIndex();
foreach ($items as $item ) {
if ($item->public) {
$item->addToIndex();
}
}
}
}

Expand All @@ -79,7 +87,7 @@ static public function reindex()
* @param string $index the index to query
* @param Request $request the client provided request
*
* @return array
* @return array
*/
public function query($index, Request $request)
{
Expand Down Expand Up @@ -202,7 +210,7 @@ public function query($index, Request $request)
* @param string $index the index to query
* @param Request $request the client provided request
*
* @return array
* @return array
*/
public function search($index, Request $request)
{
Expand Down Expand Up @@ -336,7 +344,7 @@ public function search($index, Request $request)
* @param string $index the index to query
* @param Request $request the client provided request
*
* @return array
* @return array
*/
public function collect($index, Request $request)
{
Expand Down Expand Up @@ -385,11 +393,11 @@ public function collect($index, Request $request)
$page = count($collection) - 1;
}

if ($page < 0) {
$page = 0;
if ($page < 0) {
$page = 0;
$collection = [];
} else {
$collection = $collection[$page];
$collection = $collection[$page];
}

return [
Expand Down
4 changes: 3 additions & 1 deletion public/js/main.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -18005,7 +18005,7 @@ if (module.hot) {(function () { module.hot.accept()
module.exports = {
props: ['offer']
};
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "\n<div class=\"box box-default\">\n\t<div class=\"box-header\">\n\t\t<h3 class=\"box-title\"><i class=\"fa fa-bars\"></i> General Info</h3>\n\n\t\t<div class=\"box-tools pull-right\">\n\t\t\t<button class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i></button>\n\t\t</div>\n\t</div>\n\t<div class=\"box-body form-horizontal\">\n\t\t<div class=\"form-group\">\n\t\t\t<label for=\"name\" class=\"col-sm-2 control-label\">Name:</label>\n\t\t\t<div class=\"col-sm-10\">\n\t\t\t\t<input type=\"name\" maxlength=\"255\" class=\"form-control\" id=\"name\" v-model=\"offer.name\">\n\t\t\t</div>\n\t\t</div>\n\n\t\t<div class=\"form-group\">\n\t\t\t<label for=\"description\" class=\"col-sm-2 control-label\">Description:</label>\n\t\t\t<div class=\"col-sm-10\">\n\t\t\t\t<textarea class=\"form-control\" rows=\"6\" id=\"description\" v-model=\"offer.description\"></textarea>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>\n"
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "\n<div class=\"box box-default\">\n\t<div class=\"box-header\">\n\t\t<h3 class=\"box-title\"><i class=\"fa fa-bars\"></i> General Info</h3>\n\n\t\t<div class=\"box-tools pull-right\">\n\t\t\t<button class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-minus\"></i></button>\n\t\t</div>\n\t</div>\n\t<div class=\"box-body form-horizontal\">\n\t\t<div class=\"form-group\">\n\t\t\t<label for=\"name\" class=\"col-sm-2 control-label\">Name:</label>\n\t\t\t<div class=\"col-sm-10\">\n\t\t\t\t<input type=\"name\" maxlength=\"255\" class=\"form-control\" id=\"name\" v-model=\"offer.name\">\n\t\t\t</div>\n\t\t</div>\n\n\t\t<div class=\"form-group\">\n\t\t\t<label for=\"description\" class=\"col-sm-2 control-label\">Description:</label>\n\t\t\t<div class=\"col-sm-10\">\n\t\t\t\t<textarea class=\"form-control\" rows=\"6\" id=\"description\" v-model=\"offer.description\"></textarea>\n\t\t\t</div>\n\t\t</div>\n\n\t\t<div class=\"col-xs-12\">\n\t\t\t<button class=\"btn btn-default pull-right\" v-on:click=\"offer.public = !offer.public\">\n\t\t\t\t<span v-if=\"offer.public\"><span class=\"fa fa-eye\"></span> Public</span>\n\t\t\t\t<span v-else=\"\"><span class=\"fa fa-eye-slash\"></span> Hidden</span>\n\t\t\t</button>\n\t\t</div>\n\t</div>\n</div>\n"
if (module.hot) {(function () { module.hot.accept()
var hotAPI = require("vue-hot-reload-api")
hotAPI.install(require("vue"), true)
Expand Down Expand Up @@ -19614,6 +19614,8 @@ module.exports = {

this.$refs.store.working();

console.log(this.offer);

this.$http.patch('offer/' + this.offer.id, this.offer).then(function (response) {
response.data['deleted_pictures'] = [];
_this2.$set('offer', response.data);
Expand Down
2 changes: 1 addition & 1 deletion public/js/main.min.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion resources/assets/js/components/offer/offerInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
<textarea class="form-control" rows="6" id="description" v-model="offer.description"></textarea>
</div>
</div>

<div class="col-xs-12">
<button class="btn btn-default pull-right" v-on:click="offer.public = !offer.public">
<span v-if="offer.public"><span class="fa fa-eye"></span> Public</span>
<span v-else><span class="fa fa-eye-slash"></span> Hidden</span>
</button>
</div>
</div>
</div>
</template>
Expand All @@ -29,4 +36,4 @@
module.exports = {
props: ['offer']
}
</script>
</script>
16 changes: 9 additions & 7 deletions resources/assets/js/pages/offer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<picture-upload :offer-id="offer.id"></picture-upload>

<pictures v-if="offer.pictures.length > 0"
:pictures="offer.pictures"
:pictures="offer.pictures"
:deleted="offer.deleted_pictures"
:offer-id="offer.id">
</pictures>
Expand All @@ -31,18 +31,18 @@
</div>

<div class="col-md-4 col-xs-12">
<confirmed-button icon="fa-repeat"
<confirmed-button icon="fa-repeat"
v-if="offer.id"
text="Discard Changes"
text="Discard Changes"
color="btn-info"
:action="discard"
v-ref:discard>
</confirmed-button>
</div>

<div class="col-md-4 col-xs-12">
<confirmed-button icon="fa-trash"
text="Delete Offer"
<confirmed-button icon="fa-trash"
text="Delete Offer"
color="btn-danger"
:action="deleteOffer"
v-ref:delete>
Expand Down Expand Up @@ -108,8 +108,10 @@ module.exports = {
store () {
this.$refs.store.working()
console.log(this.offer);
this.$http.patch(`offer/${this.offer.id}`, this.offer).then(response => {
response.data['deleted_pictures'] = []
response.data['deleted_pictures'] = []
this.$set('offer', response.data)
this.$refs.store.check()
}, () => {
Expand All @@ -128,4 +130,4 @@ module.exports = {
}
}
}
</script>
</script>

0 comments on commit 2217c0d

Please sign in to comment.