Skip to content

Commit

Permalink
Merge pull request #2 from iNewLegend/draft/dev-mvc
Browse files Browse the repository at this point in the history
Draft/dev mvc
  • Loading branch information
iNewLegend authored Feb 27, 2020
2 parents af82b23 + b6fd322 commit 45b15b5
Show file tree
Hide file tree
Showing 70 changed files with 1,455 additions and 983 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
npm-debug.log
node_modules
.idea
app.bundle.js

frontend/dist/mvc.bundle.js
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions api/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

namespace Config;

class Database
class Database
{
const HOST = 'localhost';
const NAME = 'market';
const USERNAME = 'root';
const PASSWORD = '';
}
const USERNAME = 'admin';
const PASSWORD = 'mysql';
}
2 changes: 2 additions & 0 deletions api/controllers/catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/**
* @file : controllers/catalog.php
* @author : Leonid Vinikov <czf.leo123@gmail.com>
*
* @desc: : Catalog Controller
*/

namespace Controllers;
Expand Down
2 changes: 1 addition & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

}, E_ALL);

//header('Access-Control-Allow-Origin: http://leonid.viewdns.net:8888');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers:X-Request-With, Content-Type');
header('Access-Control-Allow-Credentials: true'); // for cookies

Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions dev/document/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dev</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
div {
width: 500px;
height: 500px;
border: 1px solid black;
padding: 20px;
margin: 20px;
background: yellow;
}
</style>
</head>

<body>
<div id="root">
Root
</div>
<script type="module" src="index.js"></script>
</body>
</html>
88 changes: 88 additions & 0 deletions dev/document/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import Component from './modules/component';

class Container extends Component {
initialize() {
this.events = {
onRender: () => {},
}

super.initialize();
}

afterRender() {
super.afterRender();

this.events.onRender();
}

set( child ) {
this.child = child;
this.child.render();
}
/**
* Function on() : Declare event callback
*
* @param {'render'} event
* @param {{function()}} callback
*/
on(event, callback) {
switch (event) {
case 'render': {
this.events.onRender = callback;
} break;

default: {
alert(`${this.constructor.name}::on() -> invalid event type: '${event}'`);
}
}
}
}

class Page extends Container {

}

class PageContainer extends Container {

}

class CatalogPage extends Page {
onClick = () => {
alert( 'page home');
};
}



class App {
initialize() {
this.elements = {
root: document.getElementById('root'),
};

this.app = new Component(this.elements.root, `<div class="app">App</div>`);

this.pageContainer = new PageContainer( this.app, '<div class="page">Page Container</div>' );

this.pageContainer.on('render', this.onPageContainerRender.bind( this ) );

this.homePage = new CatalogPage( this.pageContainer, '<div class="homepage">Home Page</div>')

this.app.render();

this.pageContainer.render();

this.pageContainer.set( this.homePage );

}

onPageContainerRender() {
console.log('onPageContainerRender');
}
}

const app = new App();

app.initialize();


26 changes: 26 additions & 0 deletions dev/mvc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dev</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
div {
width: 500px;
height: 500px;
border: 1px solid black;
padding: 20px;
margin: 20px;
background: yellow;
}
</style>
</head>

<body>
<div id="root">
Root
</div>
<script src="../../frontend/dist/mvc.bundle.js"></script>
</body>
</html>
76 changes: 76 additions & 0 deletions dev/mvc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as Core from '../../frontend/core/index.js';
import Modules from '../../frontend/modules/index.js';

class PageContainer extends Core.Container {

}

class Page extends Core.Container {

}

class CatalogPage extends Page {
onClick = () => {
alert( 'page home');
};
}


class Item extends Modules.Component {
template() {
return '' +
'<div class"item">' +
'<h1 onClick="this.onItemClick()">Item</h1>' +
'<input type="text" onchange="this.onInputChanged( event )">' +
'</div'
;
}

onInputChanged( event ) { // controller
debugger;
}

onItemClick() {
alert('on item heading click');
}

onClick = () => {
alert('Hello from item class view');
}
}


class App {
initialize() {
this.elements = {
root: document.getElementById('root'),
};

this.app = new Core.Element(this.elements.root, `<div class="app">App</div>`);

this.pageContainer = new PageContainer( this.app, '<div class="page">Page Container</div>' );

this.pageContainer.on('render', this.onPageContainerRender.bind( this ) );

this.homePage = new CatalogPage( this.pageContainer, '<div class="homepage">Home Page</div>')

this.app.render();

this.pageContainer.set( this.homePage );
this.pageContainer.render();
}

onPageContainerRender() {
console.log( 'onPageContainerRender' );

const item = new Item( this.homePage );
item.render();
}

}

const app = new App();

app.initialize();


30 changes: 15 additions & 15 deletions js/api/cart.js → frontend/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
* @author: Leonid Vinikov <czf.leo123@gmail.com>
*/

import { Http } from './api.js';
import { Http } from 'API';

import Modules from '../modules/modules.js';
import Services from '../services/services.js';
import Modules from 'MODULES';
import Services from 'SERVICES';

export default class Cart {

/**
* Function constructor() Create Cart Api
*
* Function constructor() Create Cart Api
*
* @param {Http} http
*/
constructor(http) {
this.logger = new Modules.Logger('API.' + this.constructor.name, true);
this.logger.setOutputHandler(Services.Terminal.onOutput);

this.logger.startWith({ http });

this.http = http;
}

/**
* Function get() : Get cart
*
* @param {{function()}} callback
*
* @param {{function()}} callback
*/
get(callback) {
this.logger.startWith({ callback });
Expand All @@ -37,10 +37,10 @@ export default class Cart {

/**
* Function addItem() : Add item to cart
*
* @param {{function()}} callback
* @param {number} id
* @param {number} amount
*
* @param {{function()}} callback
* @param {number} id
* @param {number} amount
*/
addItem(callback, id, amount = 1) {
this.logger.startWith({ callback, id, amount });
Expand All @@ -52,9 +52,9 @@ export default class Cart {

/**
* Function removeItem() : Remove item from cart
*
* @param {{function()}} callback
* @param {number} id
*
* @param {{function()}} callback
* @param {number} id
*/
removeItem(callback, id) {
this.logger.startWith({ callback, id });
Expand Down
28 changes: 14 additions & 14 deletions js/api/catalog.js → frontend/api/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* @author: Leonid Vinikov <czf.leo123@gmail.com>
*/

import { Http } from './api.js';
import { Http } from 'API';

import Modules from '../modules/modules.js';
import Services from '../services/services.js';
import Modules from 'MODULES';
import Services from 'SERVICES';

export default class Catalog {

/**
* Function constructor() Create Catalog Api
*
* Function constructor() Create Catalog Api
*
* @param {Http} api
*/

Expand All @@ -29,9 +29,9 @@ export default class Catalog {

/**
* Function get() : Get catalog from the server
*
* @param {{function()}} callback
* @param {number} page
*
* @param {{function()}} callback
* @param {number} page
*/
get(callback, page = 0) {
this.logger.startWith({ callback, page });
Expand All @@ -47,9 +47,9 @@ export default class Catalog {

/**
* Function getById() : Return product with specific id's
*
* @param {{function()}} callback
* @param {number[]} ids
*
* @param {{function()}} callback
* @param {number[]} ids
*/
getByIds(callback, ids) {
this.logger.startWith({ callback, ids });
Expand All @@ -66,8 +66,8 @@ export default class Catalog {

/**
* Function getLocalProductById() : Get product from local catalog
*
* @param {number} id
*
* @param {number} id
* @return {{}|null}
*/
getLocalProductById(id) {
Expand All @@ -85,4 +85,4 @@ export default class Catalog {

return null;
}
}
}
Loading

0 comments on commit 45b15b5

Please sign in to comment.