Skip to content

Commit

Permalink
Adding Feature administration
Browse files Browse the repository at this point in the history
Still working through it. Not functional yet.
  • Loading branch information
Stardog committed Oct 27, 2017
1 parent 88c387e commit eaad5aa
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 2 deletions.
1 change: 1 addition & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function runTime(Request $request)
{
if (\Current_User::allow('stories')) {
\stories\Factory\StoryMenu::addStoryLink();
\stories\Factory\StoryMenu::featureLink();
\stories\Factory\StoryMenu::listStoryLink();
\stories\Factory\StoryMenu::adminDisplayLink();
}
Expand Down
6 changes: 6 additions & 0 deletions boost/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function stories_install(&$content)
$author = new \stories\Resource\AuthorResource;
$author->createTable($db);
$db->clearTables();

$feature = new \stories\Resource\FeatureResource;
$feature->createTable($db);
$db->clearTables();

$tag = new \stories\Resource\TagResource;
$tag->createTable($db);
Expand All @@ -41,6 +45,8 @@ function stories_install(&$content)
$tagToEntry->addDataType('tagId', 'int');
$tagToEntry->create();



} catch (\Exception $e) {
\phpws2\Error::log($e);
$db->rollback();
Expand Down
57 changes: 57 additions & 0 deletions class/Controller/Feature/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* Copyright (C) 2017 Matthew McNaney <[email protected]>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/

namespace stories\Controller\Feature;

use Canopy\Request;
use stories\Factory\FeatureFactory as Factory;
use stories\Factory\StoryMenu;
use stories\Controller\RoleController;

class Admin extends RoleController
{

/**
* @var \stories\Factory\FeatureFactory factory
*/
protected $factory;

protected function loadFactory() {
$this->factory = new Factory;
}

protected function listHtmlCommand(Request $request)
{
$this->factory->addStoryCss();
return $this->factory->scriptView('Feature', true, array('srcHttp'=>PHPWS_SOURCE_HTTP));
}

protected function listJsonCommand(Request $request)
{
return $this->factory->listing($request);
}

protected function postCommand(Request $request)
{
return array('featureId'=>$this->factory->post($request));
}

}
64 changes: 64 additions & 0 deletions class/Factory/FeatureFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* The MIT License
*
* Copyright 2017 Matthew McNaney <[email protected]>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace stories\Factory;

use stories\Resource\FeatureResource as Resource;
use phpws2\Database;
use phpws2\Settings;
use Canopy\Request;
use phpws2\Template;

/**
* Description of FeatureFactory
*
* @author Matthew McNaney <[email protected]>
*/
class FeatureFactory extends BaseFactory
{

public function build()
{
return new Resource;
}

public function post(Request $request)
{
$db = Database::getDB();
$feature = $this->build();
self::saveResource($feature);
return $feature->id;
}

public function listing(Request $request)
{
$db = Database::getDB();
$tbl = $db->addTable('storiesFeature');
$tbl->addOrderBy('sorting');
return $db->select();
}

}
58 changes: 58 additions & 0 deletions class/Resource/FeatureResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* The MIT License
*
* Copyright 2017 Matthew McNaney <[email protected]>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace stories\Resource;

/**
* Description of Feature
*
* @author Matthew McNaney <[email protected]>
*/
class FeatureResource extends BaseResource
{
protected $title;
protected $active;
protected $entries;
protected $format;
protected $columns;
protected $sorting;

protected $table = 'storiesFeature';

public function __construct()
{
parent::__construct();
$this->title = new \phpws2\Variable\TextOnly(null, 'title');
$this->title->setLimit(255);
$this->title->allowNull(true);
$this->format = new \phpws2\Variable\Attribute('landscape', 'format');
$this->format->setLimit(20);
$this->active = new \phpws2\Variable\BooleanVar(true, 'active');
$this->entries = new \phpws2\Variable\ArrayVar(null, 'entries');
$this->columns = new \phpws2\Variable\SmallInteger(2, 'columns');
$this->sorting = new \phpws2\Variable\SmallInteger(0, 'sorting');
}
}
Binary file added img/landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/left-right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/top-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions javascript/Feature/DisplayColumn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'
import React from 'react'
import PropTypes from 'prop-types'

const DisplayColumn = ({format, bsClass, entry,}) => {
const _class = 'story-feature ' + format
const thumbnailStyle = {
backgroundImage: `url('${entry.thumbnail}')`,
backgroundPosition: '50% 50%'
}
return (
<div className={bsClass}>
<div className={_class}>
<div className="story-thumbnail" style={thumbnailStyle}></div>
<div className="story-content">
<div className="story-title">
<a>
<h3>{entry.title}</h3>
</a>
</div>
<div className="story-summary">{entry.strippedSummary}</div>
<div className="published-date">Published {entry.publishDateRelative}
</div>
</div>
</div>
</div>
)
}

DisplayColumn.propTypes = {
bsClass: PropTypes.string,
format: PropTypes.string,
entry: PropTypes.object
}

DisplayColumn.defaultTypes = {}

export default DisplayColumn
126 changes: 126 additions & 0 deletions javascript/Feature/Feature.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
'use strict'
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import FeatureObj from './FeatureObj'
import FeatureList from './FeatureList'
import FeatureForm from './FeatureForm'
import Message from '../AddOn/Message'
import Waiting from '../AddOn/Waiting'

/* global $ */

export default class Feature extends Component {
constructor(props) {
super(props)
this.state = {
message: null,
currentFeature: null,
currentKey: null,
featureList: [],
loading: true,
}
this.addRow = this.addRow.bind(this)
this.closeMessage = this.closeMessage.bind(this)
this.updateFeature = this.updateFeature.bind(this)
this.loadCurrentFeature = this.loadCurrentFeature.bind(this)
}

componentDidMount() {
this.load()
}

load() {
$.ajax({
url: './stories/Feature',
dataType: 'json',
type: 'get',
success: function (data) {
const featureList = data
this.setState({featureList: featureList, loading: false})
}.bind(this),
error: function () {
this.setState({
loading: false,
message: {
text: 'Error: Could not pull feature list',
type: 'danger'
}
})
}.bind(this)
})
}

loadCurrentFeature(key) {
const feature = this.state.featureList[key]
if (feature.entries === 'null') {
feature.entries = []
}

if (feature.title === null) {
feature.title = ''
}
this.setState({currentFeature: feature, currentKey: key,})
}

addRow() {
$.ajax({
url: './stories/Feature',
dataType: 'json',
type: 'post',
success: function (data) {
const feature = FeatureObj
feature.id = data.featureId
/*
const featureList = this.state.featureList
featureList.push(feature)
*/
this.setState({currentFeature: FeatureObj, currentKey: data.featureId,})
}.bind(this),
error: function () {}.bind(this),
})
}

updateFeature(feature) {
this.setState({currentFeature: feature})
}

closeMessage() {
this.setState({message: null})
}

message() {
if (this.state.message !== null) {
const {message} = this.state
return <Message type={message.type} message={message.text} onClose={this.closeMessage}>{message.text}</Message>
}
}

getListing() {
if (this.state.loading === true) {
return <Waiting/>
} else if (this.state.currentKey !== null) {
return <FeatureForm
feature={this.state.currentFeature}
srcHttp={this.props.srcHttp}
update={this.updateFeature}/>
} else {
return <FeatureList
list={this.state.featureList}
loadCurrentFeature={this.loadCurrentFeature}/>
}
}

render() {
return (
<div>
{this.message()}
<button className="btn btn-primary mb-1" onClick={this.addRow}>Add feature row</button>
{this.getListing()}
</div>
)
}
}

Feature.propTypes = {
srcHttp: PropTypes.string
}
Loading

0 comments on commit eaad5aa

Please sign in to comment.