Пример #1
0
 public function view($path)
 {
     // Checks if the user did not provide enough information
     if (!$path['id']) {
         // Returns error message
         return DataCenterUI::message('error', 'insufficient-data');
     }
     // Gets facility space from database
     $space = DataCenterDB::getSpace($path['id']);
     // Gets plans for this space from database
     $plans = $space->getPlans();
     // Builds lookup table of locations keyed on tense
     $plansTable = DataCenterDB::buildLookupTable('tense', $plans);
     // Builds table widget for each tense
     $tables = array();
     foreach (array('present', 'future', 'past') as $tense) {
         if (isset($plansTable[$tense])) {
             $tables[$tense] = DataCenterUI::renderWidget('table', array('rows' => isset($plansTable[$tense]) ? $plansTable[$tense] : array(), 'fields' => array('name', 'space' => array('field' => 'space_name'), 'tense' => array('format' => 'option')), 'link' => array('page' => 'plans', 'action' => 'view', 'type' => 'plan', 'id' => '#id')));
         } else {
             $tables[$tense] = null;
         }
     }
     // Returns 2 columm layout with a table and a scene
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'plans')), DataCenterUI::renderLayout('tabs', $tables), DataCenterUI::renderWidget('actions', array('links' => array(array('page' => 'plans', 'type' => 'plan', 'action' => 'add', 'parameter' => array('space', $space->getId()))), 'rights' => array('change'))), DataCenterUI::renderWidget('heading', array('message' => 'space')), DataCenterUI::renderWidget('details', array('row' => $space, 'fields' => array('tense' => array('format' => 'option'), 'name', 'size' => array('fields' => array('width', 'depth', 'height'), 'glue' => ' x '), 'power'))))), DataCenterUI::renderWidget('space', array('space' => $space))));
 }
Пример #2
0
 public function view($path)
 {
     // Checks if the user did not provide enough information
     if (!$path['id']) {
         // Returns error message
         return DataCenterUI::message('error', 'insufficient-data');
     }
     // Gets location from database
     $location = DataCenterDB::getLocation($path['id']);
     // Gets meta values
     $metaValues = $location->getMetaValues();
     // Gets spaces in location from database
     $spaces = $location->getSpaces(DataCenterDB::buildSort('facility', 'space', 'name'));
     // Builds lookup table of locations keyed on tense
     $spacesTable = DataCenterDB::buildLookupTable('tense', $spaces);
     // Builds table widget for each tense
     $tables = array();
     foreach (array('present', 'future', 'past') as $tense) {
         if (isset($spacesTable[$tense])) {
             $tables[$tense] = DataCenterUI::renderWidget('table', array('rows' => $spacesTable[$tense], 'fields' => array('name'), 'link' => array('page' => 'facilities', 'type' => 'space', 'id' => '#id', 'action' => 'view')));
         } else {
             $tables[$tense] = null;
         }
     }
     // Returns 2 columm layout with tabs and a map widget
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'spaces')), DataCenterUI::renderLayout('tabs', $tables), DataCenterUI::renderWidget('actions', array('links' => array(array('page' => 'facilities', 'type' => 'space', 'action' => 'add', 'parameter' => array('location', $location->getId()))), 'rights' => array('change'))), DataCenterUI::renderWidget('heading', array('message' => 'location')), DataCenterUI::renderWidget('details', array('row' => $location, 'fields' => array('tense' => array('format' => 'option'), 'name', 'region', 'latitude', 'longitude'))))), DataCenterUI::renderWidget('map', array('location' => $location, 'jumpto' => true))));
 }
Пример #3
0
 public function view($path)
 {
     // Checks if the user did not provide enough information
     if (!$path['id']) {
         // Returns error message
         return DataCenterUI::message('error', 'insufficient-data');
     }
     // Gets plan from database
     $plan = DataCenterDB::getPlan($path['id']);
     // Gets space of plan
     $space = $plan->getSpace();
     // Gets location of space
     $location = $space->getLocation();
     // Sets location information to space
     $space->set('location_name', implode(' / ', $location->get(array('name', 'region'))));
     // Gets structure of plan from database
     $structure = $plan->getStructure(DataCenterDB::buildSort('link', 'asset', array('x', 'y')));
     // Builds tables from structure
     $tables = DataCenterDB::buildLookupTable('asset_type', $structure);
     // Builds list of rack/object assets used in plan
     if (isset($tables['rack']) && is_array($tables['rack'])) {
         foreach ($tables['rack'] as $key => $link) {
             $asset = $link->getAsset();
             $model = $asset->getModel();
             $tables['rack'][$key]->set(array('model' => implode(' / ', $model->get(array('manufacturer', 'name')))));
         }
     } else {
         $tables['rack'] = null;
     }
     // Builds javascript that references the renderable plan
     $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule');
     // Detects if this user came from a zoomed in page
     $refererPath = DataCenterPage::getRefererPath();
     $zoomOptions = array();
     if ($refererPath['page'] == $path['page'] && $refererPath['type'] == 'rack' && $refererPath['id'] !== null) {
         $rackLink = DataCenterDB::getAssetLink($refererPath['id']);
         $rack = $rackLink->getAsset();
         $zoomOptions['zoom-from-rack'] = $rack->getId();
     }
     if (!isset($tables['rack'])) {
         $tables['rack'] = array();
     }
     // Builds table of racks
     $racks = DataCenterUI::renderWidget('table', array('rows' => $tables['rack'], 'fields' => array('name', 'model', 'position' => array('fields' => array('x', 'y'), 'glue' => ' x ')), 'link' => array('page' => 'plans', 'type' => 'rack', 'action' => 'view', 'id' => '#id'), 'effects' => array(array('event' => 'onmouseover', 'script' => DataCenterJs::chain(array_merge($target, array('setRackHighlight' => array('{asset_id}', DataCenterJs::toScalar(true)))), false)), array('event' => 'onmouseout', 'script' => DataCenterJs::chain(array_merge($target, array('clearRackHighlight' => array(DataCenterJs::toScalar(true)))), false)))));
     // Returns single columm layout with a table
     return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'racks')), $racks, DataCenterUI::renderWidget('actions', array('links' => array(array('page' => 'plans', 'type' => 'rack', 'action' => 'select', 'parameter' => array('plan', $path['id']))), 'rights' => array('change'))), DataCenterUI::renderWidget('heading', array('message' => 'configuration')), DataCenterUI::renderWidget('details', array('row' => $plan, 'fields' => array('tense' => array('format' => 'option'), 'name', 'note'))), DataCenterUI::renderWidget('heading', array('message' => 'facility')), DataCenterUI::renderWidget('details', array('row' => $space, 'fields' => array('tense' => array('format' => 'option'), 'location' => array('field' => 'location_name'), 'name', 'size' => array('fields' => array('width', 'depth', 'height'), 'glue' => ' x '), 'power'))))), DataCenterUI::renderWidget('plan', array_merge(array('plan' => $plan), $zoomOptions))));
 }
Пример #4
0
 public static function render(array $parameters)
 {
     global $wgUser;
     // Sets defaults
     $parameters = array_merge(self::$defaultParameters, $parameters);
     // Begins widget
     $xmlOutput = parent::begin($parameters['class']);
     // Builds form attributes
     $formAttributes = array('id' => 'form_' . $parameters['do'], 'name' => 'form_' . $parameters['do'], 'method' => 'post', 'action' => DataCenterXml::url($parameters['action']), 'onsubmit' => DataCenterJs::buildEffect($parameters['effect'], $parameters['row']->get()));
     // Begins form
     $xmlOutput .= DataCenterXml::open('form', $formAttributes);
     // Inserts content before fields
     $xmlOutput .= $parameters['insert'];
     // Begins table
     $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']);
     // Creates array to keep track of the number of each type for auto-naming
     $count = array();
     // Loops over each field
     foreach ($parameters['fields'] as $label => $options) {
         // Begins row
         $xmlOutput .= DataCenterXml::open('tr', self::$defaultAttributes['row']);
         // Checks if the key is a numeric index
         if (is_int($label)) {
             // Adds an empty cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['empty']);
         } else {
             // Adds a label cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', $label));
         }
         // Checks if field is not an array
         if (!is_array($options)) {
             // Uses value as the input type
             $options = array();
         }
         // Checks if no type was set
         if (!isset($options['type'])) {
             // Uses "text" as the default
             $options['type'] = 'text';
         }
         // Verifies the input type is available
         if (DataCenterUI::isInput($options['type'])) {
             // Copies field for use as options for input
             $inputOptions = $options;
             // Removes type from attributes since the input doesn't need it
             unset($inputOptions['type']);
             // Check no field or fields were set
             if (!isset($inputOptions['fields']) && !isset($inputOptions['field'])) {
                 // Uses key as field
                 $inputOptions['field'] = $label;
             }
             // Checks if this is an un-named field
             if (is_int($label)) {
                 // Checks if there has been this type before
                 if (isset($count[$options['type']])) {
                     // Incriments type count
                     $count[$options['type']]++;
                 } else {
                     // Starts counting fields of this type
                     $count[$options['type']] = 0;
                 }
                 // Sets ID from type and count
                 $inputOptions['id'] = "field_{$options['type']}_{$count[$options['type']]}";
                 // Sets name of input for form processing
                 $inputOptions['name'] = "row[{$inputOptions['field']}]";
             } else {
                 // Checks if a specific field was given
                 if (isset($inputOptions['field'])) {
                     // Checks if no value was set
                     if (!isset($inputOptions['value'])) {
                         // Sets value of input from row
                         $inputOptions['value'] = $parameters['row']->get($inputOptions['field']);
                     }
                     // Sets ID from name
                     $inputOptions['id'] = "field_{$inputOptions['field']}";
                     // Sets name of input for form processing
                     $inputOptions['name'] = "row[{$inputOptions['field']}]";
                     // Alternatively checks if a list of fields were given
                 } elseif (isset($inputOptions['fields'])) {
                     // Loops over each sub-field
                     foreach ($inputOptions['fields'] as $key => $field) {
                         // Checks if sub-field is an array
                         if (is_array($inputOptions['fields'][$key])) {
                             // Uses sub-field's specific field name
                             $fieldName = $inputOptions['fields'][$key]['field'];
                         } else {
                             // Uses simple value as field name
                             $fieldName = $field;
                             // Creates arrray for sub-field options
                             $inputOptions['fields'][$key] = array();
                         }
                         // Checks if...
                         if (!isset($inputOptions['fields'][$key]['value'])) {
                             // Set the value of the field from the row
                             $inputOptions['fields'][$key]['value'] = $parameters['row']->get($fieldName);
                         }
                         // Set the ID of the field
                         $inputOptions['fields'][$key]['id'] = "field_{$fieldName}";
                         // Sets the name of the field
                         $inputOptions['fields'][$key]['name'] = "row[{$fieldName}]";
                     }
                 }
             }
             // Renders input
             $widget = DataCenterUI::renderInput($options['type'], $inputOptions);
         } else {
             // Alerts the user that the input did not exist
             $widget = DataCenterUI::message('error', 'no-ui-widget', $label);
         }
         // Adds input cell
         $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['field'], $widget);
         // Ends field row
         $xmlOutput .= DataCenterXml::close('tr');
     }
     // Checks if row is a component
     if ($parameters['meta'] && $parameters['row'] instanceof DataCenterDBComponent) {
         // Adds meta fields
         $metaFields = $parameters['row']->getMetaFields();
         $metaValues = $parameters['row']->getMetaValues();
         $valuesTable = DataCenterDB::buildLookupTable('field', $metaValues);
         foreach ($metaFields as $metaField) {
             $field = $metaField->get('field');
             $value = '';
             if (isset($valuesTable[$field][0]) && $valuesTable[$field][0] instanceof DataCenterDBMetaValue) {
                 $value = $valuesTable[$field][0]->get('value');
             }
             // Begins row
             $xmlOutput .= DataCenterXml::open('tr', self::$defaultAttributes['meta']);
             // Adds label cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['label'], $metaField->get('name'));
             // Adds input cell
             $xmlOutput .= DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::renderInput($metaField->get('format'), array('name' => 'meta[' . $field . ']', 'id' => 'meta_' . $field, 'value' => $value)));
             // Ends field row
             $xmlOutput .= DataCenterXml::close('tr');
         }
         // Adds change comment field
         $xmlOutput .= DataCenterXml::row(self::$defaultAttributes['change'], DataCenterXml::cell(self::$defaultAttributes['label'], DataCenterUI::message('field', 'change-summary')), DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::renderInput('string', array('name' => 'change[note]', 'id' => 'change_note'))));
         // Adds type of edit field
         $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'change[type]', 'value' => $parameters['type']));
     }
     // Adds cancel and submit button
     $xmlOutput .= DataCenterXML::row(DataCenterXml::cell(self::$defaultAttributes['buttons'], DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'cancel', 'class' => 'cancel', 'value' => DataCenterUI::message('label', 'cancel'))) . DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'submit', 'class' => 'submit', 'value' => DataCenterUI::message('label', $parameters['label'])))));
     // Ends table
     $xmlOutput .= DataCenterXml::close('table');
     // Adds do field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => $parameters['do']));
     // Adds token field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken()));
     // Adds success field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'success', 'value' => DataCenterXml::url($parameters['success'])));
     // Adds failure field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'failure', 'value' => DataCenterXml::url($parameters['failure'])));
     // Adds canellation field
     $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'cancellation', 'value' => DataCenterXml::url(count($parameters['cancellation']) > 0 ? $parameters['cancellation'] : $parameters['success'])));
     // Loops over hidden fields
     foreach ($parameters['hidden'] as $key => $value) {
         // Checks if key is numeric
         if (is_int($key)) {
             // Adds field with value from row
             $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => "row[{$value}]", 'value' => $parameters['row']->get($value)));
         } else {
             // Adds field with specified value
             $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => "row[{$key}]", 'value' => $value));
         }
     }
     // Appends content after fields
     $xmlOutput .= $parameters['append'];
     // Ends form
     $xmlOutput .= DataCenterXml::close('form');
     // Ends widget
     $xmlOutput .= DataCenterXml::close('div');
     // Returns the results
     return $xmlOutput;
 }