Skip to content
Permalink
Browse files

Plan Components

* New feature for Plans: Components
  • Loading branch information...
sergejey committed Mar 18, 2019
1 parent c000730 commit dcfc048f43ec3491b45508fc1f6b917c4ffeab71
@@ -1347,6 +1347,7 @@
'STYLE_FADEOUT30' => 'Opacity 30%',
'STYLE_FADEOUT10' => 'Opacity 10%',
'SEE_ALSO' => 'See also',
'PLAN_COMPONENTS' => 'Components',
'CONNECT_LOGIN_FAILED' => 'Could not login into CONNECT service. Please check username/password.',
'CONNECT_ABOUT' => 'CONNECT service allows you to organize easy access to your smarthome system by Internet. Also it provides tools for other cloud-based services like Cloud Backup, voice assistants, etc. More details available <a href="https://connect.smartliving.ru/services/s2.html">by the link</a>',
@@ -1348,6 +1348,7 @@
'STYLE_FADEOUT30' => 'Прозрачность 30%',
'STYLE_FADEOUT10' => 'Прозрачность 10%',
'SEE_ALSO' => 'Смотрите также',
'PLAN_COMPONENTS' => 'Компоненты',
'CONNECT_LOGIN_FAILED' => 'Не удалось подключиться к сервису CONNECT. Пожалуйста, проверьте указанные имя пользователя и пароль',
'CONNECT_ABOUT' => 'Cервис CONNECT позволяет Вам с помощью Облачной Синхронизации организовать простой доступ к домашней системе через сеть Интернет, а так же обеспечить работу других облачных сервисов (резервная копия, работа голосовых помощников и т.п.). Подробная информация о сервисе доступна <a href="https://connect.smartliving.ru/services/s2.html">по ссылке</a>',
@@ -325,13 +325,19 @@ private function _actionPostProperty($data)
}
$seen_plan_state[$k] = 1;
//$state = $this->_scenesDynamicElements[$k];
$state=array('ID'=>$k);
$state=array('ID'=>$k,'PROPERTY_NAME'=>$property_name,'PROPERTY_VALUE'=>$property_value);
if ($v['TEMPLATE']!='') {
$state['TEMPLATE']=$v['TEMPLATE'];
$state['ITEM']=$k;
}
if (preg_match('/^component(\d+)$/',$k,$m)) {
$state['COMPONENT_ID']=$m[1];
$state['ITEM']=$k;
}
$plans->processState($state);
$state['TEMPLATE']='';
if ($state['TEMPLATE']) {
unset($state['TEMPLATE']);
}
$send_plan_states[] = $state;
}
@@ -0,0 +1,148 @@
<?php
$plan_id=$rec['ID'];
$component_id=gr('component_id');
if ($component_id) {
$component = SQLSelectOne("SELECT * FROM plan_components WHERE PLAN_ID=" . (int)$plan_id . " AND ID=" . (int)$component_id);
if (gr('duplicate') && $component['ID']) {
$old_id=$component['ID'];
unset($component['ID']);
$component['TITLE'].=' (copy)';
$component['REPLACE_NAME']='';
$component['ID']=SQLInsert('plan_components',$component);
$old_data=SQLSelect("SELECT * plan_components_data WHERE COMPONENT_ID=".$old_id);
foreach($old_data as $data_item) {
unset($data_item['ID']);
$data_item['COMPONENT_ID']=$component['ID'];
SQLInsert('plan_components_data',$data_item);
}
$this->redirect("?view_mode=".$this->view_mode."&id=".$plan_id."&tab=".$this->tab."&component_id=".$component['ID']);
}
if (gr('delete') && $component['ID']) {
SQLExec("DELETE FROM plan_components_data WHERE COMPONENT_ID=".$component['ID']);
SQLExec("DELETE FROM plan_components WHERE ID=".$component['ID']);
$this->redirect("?view_mode=".$this->view_mode."&id=".$plan_id."&tab=".$this->tab);
}
if ($this->mode=='update') {
$ok=1;
$component['PLAN_ID']=$plan_id;
$component['TITLE']=gr('component_title');
if (!$component['TITLE']) {
$ok=0;
$out['ERR_TITLE'];
}
$component['COMPONENT_NAME']=gr('component_component_name');
if (!$component['COMPONENT_NAME']) {
$ok=0;
$out['ERR_COMPONENT_NAME']=1;
}
$component['REPLACE_NAME']=gr('component_replace_name','trim');
$do_on_click=gr('do_on_click');
if ($do_on_click=='run_code') {
$component['CODE']=gr('code');
} else {
$component['CODE']='';
}
if ($do_on_click=='run_script') {
$component['SCRIPT_ID']=gr('script_id');
} else {
$component['SCRIPT_ID']=0;
}
if ($do_on_click=='open_menu') {
$component['MENU_ITEM_ID']=gr('menu_item_id');
} else {
$component['MENU_ITEM_ID']=0;
}
if ($do_on_click=='run_method') {
$component['ACTION_OBJECT']=gr('action_object');
$component['ACTION_METHOD']=gr('action_method');
} else {
$component['ACTION_OBJECT']='';
$component['ACTION_METHOD']='';
}
if ($do_on_click=='show_homepage') {
$component['HOMEPAGE_ID']=gr('homepage_id','int');
} else {
$component['HOMEPAGE_ID']=0;
}
if ($do_on_click=='show_url') {
$component['EXT_URL']=gr('ext_url');
} else {
$component['EXT_URL']='';
}
if ($ok) {
if ($component['ID']) {
SQLUpdate('plan_components',$component);
} else {
$component['ID']=SQLInsert('plan_components',$component);
}
$out['OK']=1;
//$this->redirect("?view_mode=".$this->view_mode."&id=".$plan_id."&tab=".$this->tab);
} else {
$out['ERR']=1;
}
}
if ($component['COMPONENT_NAME'] && file_exists(DIR_MODULES.$this->name.'/components/'.$component['COMPONENT_NAME'].'.class.php')) {
include_once (DIR_MODULES.$this->name.'/components/'.$component['COMPONENT_NAME'].'.class.php');
$object=new $component['COMPONENT_NAME']($component['ID']);
$properties=$object->getProperties();
if ($this->mode=='update') {
SQLExec("DELETE FROM plan_components_data WHERE COMPONENT_ID=".(int)$component['ID']);
foreach($properties as $property) {
$property_rec=array('COMPONENT_ID'=>$component['ID']);
$property_rec['PROPERTY_NAME']=$property['NAME'];
if ($property['TYPE']=='int') {
$property_rec['PROPERTY_VALUE'] = gr('property_'.$property['NAME'], 'int');
} elseif ($property['TYPE']=='linked_property') {
$property_rec['LINKED_OBJECT'] = gr('property_'.$property['NAME'] . '_linked_object');
$property_rec['LINKED_PROPERTY'] = gr('property_'.$property['NAME'] . '_linked_property');
} else {
$property_rec['PROPERTY_VALUE']=gr('property_'.$property['NAME'],'trim');
}
SQLInsert('plan_components_data',$property_rec);
}
$properties=$object->getProperties();
}
$out['RENDER_SVG']=$object->getSVG(array('x'=>0,'y'=>0));
$out['PROPERTIES']=$properties;
}
if (is_array($component)) {
foreach ($component as $k => $v) {
$out['COMPONENT_' . $k] = htmlspecialchars($v);
}
}
$out['COMPONENT_ID']=$component_id;
$out['HOMEPAGES']=SQLSelect("SELECT ID, TITLE FROM layouts ORDER BY TITLE");
$out['SCRIPTS']=SQLSelect("SELECT ID, TITLE FROM scripts ORDER BY TITLE");
$menu_items=SQLSelect("SELECT ID, TITLE, PARENT_ID FROM commands WHERE EXT_ID=0 ORDER BY PARENT_ID, TITLE");
$titles=array();
foreach($menu_items as $k=>$v) {
$titles[$v['ID']]=$v['TITLE'];
}
$total=count($menu_items);
for($i=0;$i<$total;$i++) {
if ($titles[$menu_items[$i]['PARENT_ID']]) {
$menu_items[$i]['TITLE']=$titles[$menu_items[$i]['PARENT_ID']].' &gt; '.$menu_items[$i]['TITLE'];
}
}
$out['MENU_ITEMS']=$menu_items;
}
$qry="1";
$components=SQLSelect("SELECT * FROM plan_components WHERE PLAN_ID=".(int)$plan_id." AND $qry ORDER BY TITLE");
$out['COMPONENTS']=$components;
$out['TYPES']=$this->getComponentTypes();
$out['ITEMS']=$this->getImageItems($plan_id);
@@ -0,0 +1,123 @@
<?php
include_once DIR_MODULES . 'plans/plan_component.class.php';
class switch_sample extends plan_component {
function __construct($id)
{
$this->name=str_replace('.class.php','',basename(__FILE__));
parent::__construct($id);
}
function getProperties()
{
$properties = parent::getProperties();
$properties[] = array(
'NAME' => 'color',
'TITLE' => LANG_COLOR,
'TYPE' => 'rgb',
'DEFAULT' => '#ff0000'
);
$properties[] = array(
'NAME' => 'bgcolor',
'TITLE' => LANG_COLOR.' (background)',
'TYPE' => 'select',
'DATA' => '#ff0000=Red|#00ff00=Green|#0000ff=Blue',
'DEFAULT' => '#ff0000'
);
$properties[] = array(
'NAME' => 'value',
'TITLE' => LANG_VALUE,
'TYPE' => 'linked_property'
);
/*
$properties[] = array(
'NAME' => 'value_min',
'TITLE' => 'Min',
'TYPE' => 'int',
'DEFAULT' => '0'
);
$properties[] = array(
'NAME' => 'value_max',
'TITLE' => 'Max',
'TYPE' => 'int',
'DEFAULT' => '100'
);
*/
$this->processProperties($properties);
return $properties;
}
function getSVG($attributes)
{
$x=(int)$attributes['x'];
$y=(int)$attributes['y'];
$data=$this->getData();
$current_value=(int)$data['value']['VALUE'];
if ($data['value']['VALUE']) {
$data['value_proc']['VALUE']=100;
} else {
$data['value_proc']['VALUE']=0;
}
$bgcolor=$data['bgcolor']['VALUE'];
$width=(int)$attributes['width'];
if (!$width) $width=200;
$height=(int)$attributes['height'];
if (!$height) $height=20;
$svg="<svg width='$width' height='$height' x='$x' y='$y'>";
$svg.="<rect x='0' y='0' width='100%' height='$height' style=\"fill:{$bgcolor};stroke-width:3;stroke:rgb(0,0,0)\"/>";
$svg.="<rect x='0' y='0' width='%value_proc%%' id='procElem{$this->component_id}' height='$height' style=\"fill:%color%;stroke-width:3;stroke:rgb(0,0,0)\"/>";
$svg.="</svg>";
foreach($data as $k=>$v) {
$svg=str_replace('%'.$k.'%',$v['VALUE'],$svg);
}
return $svg;
}
function getJavascript()
{
$data=$this->getData();
$prop_name=strtolower($data['value']['LINKED_OBJECT'].'.'.$data['value']['LINKED_PROPERTY']);
$code = <<<EOD
function componentUpdated{$this->component_id}(property_name,property_value) {
if (property_name=='$prop_name') {
var elem=$('#procElem{$this->component_id}');
if (property_value=='1') {
elem.attr('widthNum','5');
elem.animate(
{'widthNum':100},
{
step: function(widthNum){
$(this).attr('width', widthNum+'%');
},
duration: 200
}
);
} else {
elem.attr('widthNum','100');
elem.animate(
{'widthNum':0},
{
step: function(widthNum){
$(this).attr('width', widthNum+'%');
},
duration: 200
}
);
}
}
}
EOD;
return $code;
}
}
@@ -0,0 +1,70 @@
<?php
class plan_component extends stdClass
{
public $name;
public $component_id;
function __construct($id)
{
$this->component_id = $id;
}
function getDataProperties()
{
}
function getSVG($attributes)
{
}
function getProperties()
{
$basic_properties = array();
return $basic_properties;
}
function getData()
{
$data = array();
if ($this->component_id) {
$data_items = SQLSelect("SELECT * FROM plan_components_data WHERE COMPONENT_ID=" . (int)$this->component_id);
foreach ($data_items as $data_item) {
$data[$data_item['PROPERTY_NAME']] = array('VALUE' => $data_item['PROPERTY_VALUE'], 'LINKED_OBJECT' => $data_item['LINKED_OBJECT'], 'LINKED_PROPERTY' => $data_item['LINKED_PROPERTY']);
if ($data_item['LINKED_OBJECT'] && $data_item['LINKED_PROPERTY']) {
$data[$data_item['PROPERTY_NAME']]['VALUE'] = getGlobal($data_item['LINKED_OBJECT'] . "." . $data_item['LINKED_PROPERTY']);
}
}
}
return $data;
}
function processProperties(&$properties)
{
$data = $this->getData();
foreach ($properties as &$property) {
if ($property['TYPE'] == 'select') {
$items_data = explode('|', $property['DATA']);
foreach ($items_data as $item) {
if (preg_match('/^(.+?)=(.+)$/', $item, $m)) {
$property['OPTIONS'][] = array('VALUE' => $m[1], 'TITLE' => $m[2]);
} else {
$property['OPTIONS'][] = array('VALUE' => $item, 'TITLE' => $item);
}
}
}
if (isset($data[$property['NAME']])) {
$property['VALUE'] = $data[$property['NAME']]['VALUE'];
$property['LINKED_OBJECT'] = $data[$property['NAME']]['LINKED_OBJECT'];
$property['LINKED_PROPERTY'] = $data[$property['NAME']]['LINKED_PROPERTY'];
} else {
$property['VALUE'] = $property['DEFAULT'];
}
}
}
function getJavascript()
{
}
}
Oops, something went wrong.

0 comments on commit dcfc048

Please sign in to comment.
You can’t perform that action at this time.