Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kudos extension #339

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25,132 changes: 25,132 additions & 0 deletions extensions/kudos/admin/dist/kudos.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions extensions/kudos/admin/dist/kudos.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions extensions/kudos/admin/kudos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once __DIR__.'/src/Extension.php';
require_once __DIR__.'/src/Controller.php';
require_once __DIR__.'/src/ApiController.php';

// Migrations
require_once __DIR__.'/src/Migrations/CreateTables.php';

15 changes: 15 additions & 0 deletions extensions/kudos/admin/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"label": "Kudos Admin",
"menu": ["Kudos", "fa-th"],
"order": "0",
"icon": "fa-random",
"user_levels": [
"Admin"
],
"dashboardPosition": 0,
"permissions": [],
"model_namespace": "\\KudosAdmin\\Common\\Model",
"manager": "\\KudosAdmin\\Extension",
"controller": "\\KudosAdmin\\Controller",
"headless": false
}
58 changes: 58 additions & 0 deletions extensions/kudos/admin/src/ApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace KudosAdmin;

use Classes\IceApiController;
use Classes\IceResponse;
use Classes\RestEndPoint;

class ApiController extends IceApiController
{
public function registerEndPoints() {
// REST Api get request
self::register(
REST_API_PATH . 'kudos/echo', self::GET, function ($pathParams = null) {
(new RestEndPoint())->sendResponse(
new IceResponse(
IceResponse::SUCCESS,
'Hello from KudosAdmin extension'
)
);
});

// REST Api get request with path parameters
self::register(
REST_API_PATH . 'kudos/echo/(:any)', self::GET, function ($parameter) {
(new RestEndPoint())->sendResponse(
new IceResponse(
IceResponse::SUCCESS,
'Hello from KudosAdmin extension with data:'.$parameter
)
);
});

// REST Api get request with two path parameters
self::register(
REST_API_PATH . 'kudos/echo/(:any)/(:num)', self::GET, function ($parameter1, $parameter2) {
(new RestEndPoint())->sendResponse(
new IceResponse(
IceResponse::SUCCESS,
'Hello from KudosAdmin extension with parameter1:'.$parameter1.' and parameter2:'.$parameter2
)
);
});

// REST Api post request
self::register(
REST_API_PATH . 'kudos/echo', self::POST, function ($pathParams = null) {
$restEndpoint = new RestEndPoint();
$data = $restEndpoint->getRequestBody();
$restEndpoint->sendResponse(
new IceResponse(
IceResponse::SUCCESS,
'Hello from KudosAdmin extension (POST request) with body:'.json_encode($data)
)
);
});
}
}

9 changes: 9 additions & 0 deletions extensions/kudos/admin/src/Common/Model/Kudos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace KudosAdmin\Common\Model;

use Model\BaseModel;

class EmployeeKudos extends BaseModel
{
public $table = 'EmployeeKudos';
}
15 changes: 15 additions & 0 deletions extensions/kudos/admin/src/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace KudosAdmin;

use Classes\IceController;
use Classes\IceResponse;

class Controller extends IceController
{
public function testAction($req): IceResponse
{
return new IceResponse(IceResponse::SUCCESS, 'Echo from server: '.$req->data);
}
}

24 changes: 24 additions & 0 deletions extensions/kudos/admin/src/Extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace KudosAdmin;

use Classes\BaseService;
use Classes\IceExtension;
use KudosAdmin\Migrations\CreateTables;

class Extension extends IceExtension
{

public function initialize() {
// BaseService::getInstance()->registerExtensionMigration(new CreateTables());
}

public function setupModuleClassDefinitions() {
// $this->addModelClass('ClassName');
}

public function setupRestEndPoints() {
(new ApiController())->registerEndPoints();
}
}

40 changes: 40 additions & 0 deletions extensions/kudos/admin/src/Migrations/CreateTables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace KudosAdmin\Migrations;

use Classes\Migration\AbstractMigration;
use Classes\Migration\MigrationInterface;

class CreateTables extends AbstractMigration implements MigrationInterface
{

public function getName() {
return 'kudos_create_table';
}

public function up() {
$sql = <<<'SQL'
create table EmployeeKudos
(
id bigint auto_increment primary key,
employee bigint null,
sender bigint not null,
message varchar(500) charset utf8 not null,
created datetime null,
updated datetime null,
CONSTRAINT `Fk_EmployeeKudos_Sender` FOREIGN KEY (`sender`) REFERENCES `Employees` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `Fk_EmployeeKudos_Employee` FOREIGN KEY (`employee`) REFERENCES `Employees` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
)
collate=utf8mb4_unicode_ci;
SQL;
$this->executeQuery($sql);
}

public function down() {
$sql = <<<'SQL'
DROP TABLE IF EXISTS `EmployeeKudos`;
SQL;
return $this->executeQuery($sql);
}
}

11 changes: 11 additions & 0 deletions extensions/kudos/admin/web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
use Classes\PermissionManager;

$moduleData = [
'controller_url' => CLIENT_BASE_URL.'service.php',
'user_level' => $user->user_level,
];
?><div class="span9"><div id="content"></div></div>
<script>
initKudosAdmin(<?=json_encode($moduleData)?>);
</script>
34 changes: 34 additions & 0 deletions extensions/kudos/admin/web/js/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ExtensionController from '../../../../../web/api/ExtensionController';

class KudosAdminExtensionController extends ExtensionController {
handleTestAction() {
/**
* The `testAction` should be defined in the `Controller.php` class
*/
this.handleRequest(
'testAction',
{ data: 'message from client' },
).then((response) => {
console.log(response);
});
}

makeSomeTestApiRequests() {
/**
* The endpoints are defined in ApiController.php
*/

// Making a simple GET request
this.getApiClient().get('kudos/echo').then((response) => {
console.log('Response to kudos/echo GET request:');
console.log(response);
});

// Making a simple POST request
this.getApiClient().post('kudos/echo', { browserTime: (new Date()).getTime() }).then((response) => {
console.log('Response to kudos/echo POST request:');
console.log(response);
});
}
}
export default KudosAdminExtensionController;
19 changes: 19 additions & 0 deletions extensions/kudos/admin/web/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import KudosAdminExtensionController from './controller';
import KudosAdminModule from './module';

function init(data) {
// Exposing modJsList and modJs is required to make sure IceHrm core features
// are working as expected
window.modJsList = [];
window.modJs = new KudosAdminModule('KudosAdmin');
window.modJsList.push(window.modJs);

// Defining a controller to handle requests from the extension
window.kudosExtensionController = new KudosAdminExtensionController(
'admin=kudos',
data.controller_url,
);
}

window.initKudosAdmin = init;
28 changes: 28 additions & 0 deletions extensions/kudos/admin/web/js/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Each extension should define and expose a module class extending `ExtensionModuleBase`.
* This is to make sure that the extension is compatible with the core features of IceHrm.
*/
import React from 'react';
import ReactDOM from "react-dom";
import ExtensionModuleBase from "../../../../../web/api/ExtensionModuleBase";
import KudosAdminExtensionView from "./view";

class KudosAdminModule extends ExtensionModuleBase {
/**
* This method should be used to mount the React component responsible for the extension view.
* This method will be called after IceHrm core and frontend is loaded.
*/
showExtensionView() {
// Mounting your extension
// The DOM element with id `content` is defined in the `index.php` file of the extension
ReactDOM.render(<KudosAdminExtensionView />, document.getElementById('content'));

// Calling a method in the controller (just to show how it works)
window.kudosExtensionController.handleTestAction();

// Sending some test api requests to endpoints defined in ApiController.php
window.kudosExtensionController.makeSomeTestApiRequests();
}
}

export default KudosAdminModule;
18 changes: 18 additions & 0 deletions extensions/kudos/admin/web/js/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { Empty } from 'antd';

class KudosAdminExtensionView extends React.Component {
render() {
return (
<Empty
description={(
<span>
Stating point to build an awesome IceHrm extension.
</span>
)}
/>
);
}
}

export default KudosAdminExtensionView;