diff --git a/client/src/app/main/main-home/main-home-page-portal.js b/client/src/app/main/main-home/main-home-page-portal.js index 311c5c8f..43261fe5 100644 --- a/client/src/app/main/main-home/main-home-page-portal.js +++ b/client/src/app/main/main-home/main-home-page-portal.js @@ -1,15 +1,21 @@ import React from 'react'; import classNames from 'classnames'; + import Widget from 'core-components/widget'; +import Card from 'core-components/card'; +import i18n from 'lib-app/i18n'; class MainHomePagePortal extends React.Component { render() { return ( - support portal + + + ); + } } diff --git a/client/src/core-components/card.js b/client/src/core-components/card.js new file mode 100644 index 00000000..6022fb6b --- /dev/null +++ b/client/src/core-components/card.js @@ -0,0 +1,32 @@ +import React from 'react'; +import Icon from 'core-components/icon'; +import classNames from 'classnames'; + +class Card extends React.Component{ + static propTypes = { + description: React.PropTypes.string, + title: React.PropTypes.string, + icon: React.PropTypes.string, + color: React.PropTypes.string + }; + + render(){ + return( +
+
+
{this.props.title}
+
{this.props.description}
+
+ ) + } + getClass(){ + var classes = { + 'card': true, + 'card_red': (this.props.color === 'red'), + 'card_blue': (this.props.color === 'blue'), + 'card_green': (this.props.color === 'green') + }; + return classNames(classes); + } +} +export default Card; diff --git a/client/src/core-components/card.scss b/client/src/core-components/card.scss new file mode 100644 index 00000000..c978dc07 --- /dev/null +++ b/client/src/core-components/card.scss @@ -0,0 +1,26 @@ +@import "../scss/vars"; + +.card{ + padding: 15px; + width: 200px; + height: 260px; + color: white; + display: inline-block; + margin-right: 10px; + border-radius: 4px; + &__title{ + font-variant: small-caps; + font-size: 20px; + } + &__description{ + } + &_red{ + background-color: $primary-red; + } + &_blue{ + background-color: $secondary-blue; + } + &_green{ + background-color: $primary-green; + } +} diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index 044c4529..5edfc3fa 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -1,5 +1,8 @@ export default { 'WELCOME': 'Welcome', + 'TICKETS': 'Tickets', + 'ARTICLES': 'Articles', + 'ACCOUNT': 'Account', 'SUBMIT': 'Submit', 'LOG_IN': 'Log in', 'SIGN_UP': 'Sign up', @@ -16,6 +19,9 @@ export default { 'CREATE_TICKET_DESCRIPTION': 'This is a form for creating tickets. Fill the form and send us your issues/doubts/suggestions. Our support system will answer it as soon as possible.', 'TICKET_LIST': 'Ticket List', 'TICKET_LIST_DESCRIPTION': 'Here you can find a list of all tickets you have sent to our support team.', + 'TICKETS_DESCRIPTION': 'A random text about tickets', + 'ARTICLES_DESCRIPTION': 'A random text about articles', + 'ACCOUNT_DESCRIPTION': 'A random text about account', 'DEPARTMENT': 'Department', 'AUTHOR': 'Author', 'DATE': 'Date', diff --git a/client/src/scss/_vars.scss b/client/src/scss/_vars.scss index 5d3b1592..dbae3a5c 100644 --- a/client/src/scss/_vars.scss +++ b/client/src/scss/_vars.scss @@ -5,6 +5,8 @@ $secondary-red: #FB6362; $primary-blue: #414A59; $secondary-blue: #20B8c5; +$primary-green: #82CA9C; + $very-light-grey: #F7F7F7; $light-grey: #EEEEEE; $grey: #E7E7E7; diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index 6b10b00a..bf840b8d 100644 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -50,7 +50,6 @@ class CreateController extends Controller { $ticket = new Ticket(); $ticket->setProperties(array( - 'ticketId' => '', 'title' => $this->title, 'content' => $this->content, 'language' => $this->language, diff --git a/server/libs/Hashing.php b/server/libs/Hashing.php index 7b296357..aa402cf5 100644 --- a/server/libs/Hashing.php +++ b/server/libs/Hashing.php @@ -10,4 +10,7 @@ class Hashing { public static function generateRandomToken() { return md5(uniqid(rand())); } + public static function getRandomTicketNumber($min,$max) { + return rand($min,$max); + } } \ No newline at end of file diff --git a/server/models/DataStore.php b/server/models/DataStore.php index 2799c289..0248aaa9 100644 --- a/server/models/DataStore.php +++ b/server/models/DataStore.php @@ -16,6 +16,9 @@ abstract class DataStore { return ($bean) ? new static($bean) : new NullDataStore(); } + public static function count() { + return RedBean::count(static::TABLE); + } private static function validateProp($propToValidate) { $validProp = false; diff --git a/server/models/Ticket.php b/server/models/Ticket.php index ff20334a..311df4b3 100644 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -26,18 +26,35 @@ class Ticket extends DataStore { public static function getTicket($value, $property = 'id') { return parent::getDataStore($value, $property); } - + public function getDefaultProps() { return array( - 'owner' => null + 'owner' => null, + 'ticketNumber' => $this->generateUniqueTicketNumber() ); } - + public function store() { parent::store(); - + if ($this->author instanceof User) { $this->author->store(); } } -} \ No newline at end of file + public function generateUniqueTicketNumber() { + $ticketQuantity = Ticket::count('ticket'); + $minValue = 100000; + $maxValue = 999999; + + if ($ticketQuantity === 0) { + $ticketNumber = Hashing::getRandomTicketNumber($minValue, $maxValue); + } else { + $firstTicketNumber = Ticket::getTicket(1)->ticketNumber; + $gap = 176611; + + $ticketNumber = ($firstTicketNumber - $minValue + $ticketQuantity * $gap) % ($maxValue - $minValue + 1) + $minValue; + } + + return $ticketNumber; + } +} diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index e9209969..979895d9 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -108,8 +108,42 @@ describe '/ticket/create' do (ticket['closed']).should.equal('0') (ticket['department_id']).should.equal('1') (ticket['author_id']).should.equal($csrf_userid) + (ticket['ticket_number'].size).should.equal(6) ticket_user_relation = $database.getRow('ticket_user','1','ticket_id') (ticket_user_relation['user_id']).should.equal($csrf_userid) end + + it 'should set correct ticket number' do + result = request('/ticket/create',{ + title: 'Winter is coming1', + content: 'The north remembers', + departmentId: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + result = request('/ticket/create',{ + title: 'Winter is coming2', + content: 'The north remembers', + departmentId: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + result = request('/ticket/create',{ + title: 'Winter is coming3', + content: 'The north remembers', + departmentId: 1, + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + ticket0 = $database.getRow('ticket','Winter is coming','title')['ticket_number'].to_i + ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i + ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i + ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i + + (ticket1).should.equal((ticket0 - 100000 + 1 * 176611) % 900000 + 100000) + (ticket2).should.equal((ticket0 - 100000 + 2 * 176611) % 900000 + 100000) + (ticket3).should.equal((ticket0 - 100000 + 3 * 176611) % 900000 + 100000) + end end