public function manage($path) { // Checks if... if (!$path['id'] && is_scalar($path['parameter'])) { // Creates new asset with default parameters $asset = DataCenterDBAsset::newFromType($path['type'], array('model' => $path['parameter'], 'tense' => 'present')); // Sets action specific parameters $formParameters = array('label' => 'deploy', 'hidden' => array('model'), 'success' => array('page' => 'assets', 'type' => $path['type']), 'type' => 'deploy'); $headingParameters = array('message' => 'deploying-asset-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets asset from database $asset = DataCenterDB::getAsset($path['type'], $path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'assets', 'type' => $path['type'], 'action' => 'view', 'id' => $path['id']), 'type' => 'manage'); $headingParameters = array('message' => 'managing-asset-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Gets model from database $model = $asset->getModel(); // Gets list of locations $locations = DataCenterDB::getLocations(); // Completes form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'assets', 'type' => $path['type']), 'row' => $asset, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'location' => array('type' => 'list', 'rows' => $locations, 'labels' => array('name', 'region'), 'glue' => ' / '), 'serial' => array('type' => 'string'), 'asset' => array('type' => 'string')))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'model-type', 'type' => $path['type'])), DataCenterUI::renderWidget('details', array_merge(self::$options[$path['type']]['details'], array('row' => $model))))))); }
public function history($path) { if ($path['type'] == 'location') { $facility = DataCenterDB::getLocation($path['id']); } elseif ($path['type'] == 'space') { $facility = DataCenterDB::getSpace($path['id']); } else { return null; } return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'history-type', 'subject' => DataCenterUI::message('type', $path['type']))), DataCenterUI::renderWidget('history', array('component' => $facility)))))); }
public static function render(array $parameters) { global $wgUser; // Gets current path $path = DataCenterPage::getPath(); // Sets Defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); // Adds result type menu $currentTarget = null; $currentNum = null; $menuItems = array(); foreach (self::$targets as $target) { $numMatches = DataCenterDB::numMatches($target['category'], $target['type'], $target['fields'], $parameters['query']); if ($numMatches == 0) { continue; } $fusedType = $target['category'] . '.' . $target['type']; if (!$path['type']) { $path['type'] = $fusedType; } if ($path['type'] == $fusedType) { $currentTarget = $target; $currentNum = $numMatches; $state = 'current'; } else { $state = 'normal'; } $typePath = array_merge($path, array('type' => $target['category'] . '.' . $target['type'])); $menuItems[] = DataCenterXml::div(array('class' => 'type-' . $state), DataCenterXml::link(DataCenterUI::message('results', $target['category'] . '-' . $target['type'], $numMatches), $typePath)); } $resultItems = array(); if (!$currentTarget) { $xmlOutput .= DataCenterUI::renderWidget('body', array('message' => 'notice-no-results', 'style' => 'notice')); } else { $joins = array(); if ($currentTarget['class'] == 'DataCenterDBAsset') { $joins = array_merge_recursive(DataCenterDB::buildJoin('model', $currentTarget['type'], 'id', 'asset', $currentTarget['type'], 'model', array('name', 'manufacturer')), DataCenterDB::buildJoin('facility', 'location', 'id', 'asset', $currentTarget['type'], 'location', array('name' => 'location_name'))); } // Gets search results $results = DataCenterDB::getMatches($currentTarget['class'], $currentTarget['category'], $currentTarget['type'], $currentTarget['fields'], $parameters['query'], array_merge_recursive($joins, DataCenterDB::buildRange($path))); // Adds types $xmlOutput .= DataCenterXml::div(array('class' => 'types'), implode($menuItems)); // Adds results $xmlOutput .= DataCenterXml::div(array('class' => 'results'), DataCenterUI::renderWidget('table', array_merge($currentTarget['table'], array('rows' => $results, 'num' => $currentNum)))); } // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
private static function markerOptions(array $parameters, $location) { // Begins window $xmlOutput = DataCenterXml::open('div', array('class' => 'window')); // Adds heading $xmlOutput .= DataCenterXml::div(array('class' => 'heading'), DataCenterXml::link($location->get('name'), array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $location->getId()))); // Gets number of spaces in location $numSpaces = DataCenterDB::numSpaces(DataCenterDB::buildCondition('facility', 'space', 'location', $location->getId())); // Adds body $xmlOutput .= DataCenterXml::div(array('class' => 'body'), DataCenterXml::div(array('class' => 'region'), $location->get('region')) . DataCenterXml::div(array('class' => 'spaces'), DataCenterUI::message('label', 'num-spaces', $numSpaces))); // Ends window $xmlOutput .= DataCenterXml::close('div'); // Returns JavaScript object of options return DataCenterJs::toObject(array('content' => $xmlOutput)); }
private static function renderModel($parameters, $structure, $level = 0) { $xmlOutput = ''; foreach ($structure as $model) { $modelLink = DataCenterDB::getModelLink($model->get('link')); if (!DataCenterPage::userCan('change')) { $rowAttributes = array(); } elseif ($level == 0 && count($parameters['link']) > 0) { $rowAttributes = array_merge(array('class' => 'link'), DataCenterXml::buildLink($parameters['link'], $model)); } else { $rowAttributes = array('class' => 'mute'); } $xmlOutput .= DataCenterXml::row($rowAttributes, DataCenterXml::cell(DataCenterXml::div(array('style' => 'padding-left:' . $level * 15 . 'px'), $modelLink->get('name'))) . DataCenterXml::cell(array('align' => 'right'), $modelLink->get('quantity')) . DataCenterXml::cell($model->get('name')) . DataCenterXml::cell(DataCenterUI::message('type', $model->getType()))); $xmlOutput .= self::renderModel($parameters, $model->getStructure(), $level + 1); } return $xmlOutput; }
public function __construct(array $path) { // Actions if ($path['id']) { if (DataCenterPage::userCan('remove')) { $this->actions['remove'] = array('page' => 'plans', 'type' => $path['type'], 'action' => 'remove', 'id' => $path['id']); } if (DataCenterPage::userCan('change')) { $this->actions['configure'] = array('page' => 'plans', 'type' => $path['type'], 'action' => 'configure', 'id' => $path['id']); } $this->actions['view'] = array('page' => 'plans', 'type' => $path['type'], 'action' => 'view', 'id' => $path['id']); } // Trail if ($path['id']) { $type = $path['type']; $id = $path['id']; } elseif (is_array($path['parameter']) && count($path['parameter']) >= 2) { $type = $path['parameter'][0]; $id = $path['parameter'][1]; } if (isset($id, $type)) { $include = false; foreach (array_reverse(self::$steps) as $step) { if ($step == $type) { $include = true; } if (!$include) { continue; } if ($step == 'plan') { $plan = DataCenterDB::getPlan($id); $this->trail[$plan->get('name')] = array('page' => 'plans', 'type' => 'plan', 'action' => 'view', 'id' => $plan->getId()); } else { $link = DataCenterDB::getLink('asset', $id); $this->trail[$link->get('name')] = array('page' => 'plans', 'type' => $step, 'action' => 'view', 'id' => $link->getId()); $id = $link->get('parent_link'); if ($id == null) { $id = $link->get('plan'); } } } $this->trail = array_reverse($this->trail); } }
public function configure($path) { // Detects mode if (!$path['id']) { // Creates new component $field = DataCenterDBMetaField::newFromValues(); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'settings', 'type' => 'field')); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'adding-type', 'type' => 'field'))); } else { // Gets component from database $field = DataCenterDB::getMetaField($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'settings', 'type' => 'field', 'action' => 'view', 'id' => $path['id'])); $rows = array(DataCenterUI::renderWidget('heading', array('message' => 'configuring-type', 'type' => 'field')), DataCenterUI::renderWidget('body', array('message' => 'important-configuring-field', 'style' => 'important'))); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array_merge($rows, array(DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'settings', 'type' => 'field'), 'row' => $field, 'fields' => array('name' => array('type' => 'string'), 'format' => array('type' => 'list', 'enum' => array('category' => 'meta', 'type' => 'field', 'field' => 'format'))))))))), ' ')); }
public function edit($path) { // Checks if... if (!$path['id'] && is_array($path['parameter']) && count($path['parameter'] >= 2) && $path['parameter'][0] == 'location') { // Creates new facility with default parameters $space = DataCenterDBSpace::newFromValues(array('location' => $path['parameter'][1], 'tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'space')))); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'hidden' => array($path['parameter'][0]), 'success' => array('page' => 'facilities', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1]), 'type' => 'add'); $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets facility from database $space = DataCenterDB::getSpace($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('location', 'id'), 'success' => array('page' => 'facilities', 'type' => 'space', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit'); $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Builds JavaScript to access renderable facility $jsTarget = DataCenterJs::chain(array("dataCenter.renderer.getTarget" => DataCenterJs::toScalar('space'), 'getModule'), false); // Complete form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'space'), 'row' => $space, 'fields' => array('tense' => array('type' => 'tense', 'disable' => array('past')), 'name' => array('type' => 'string'), 'width' => array('type' => 'number', 'effect' => $jsTarget . '.setWidth( {this}.value, true );'), 'height' => array('type' => 'number', 'effect' => $jsTarget . '.setHeight( {this}.value, true );'), 'depth' => array('type' => 'number', 'effect' => $jsTarget . '.setDepth( {this}.value, true );'), 'power' => array('type' => 'number', 'min' => 0, 'max' => 100000, 'step' => 100)))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('space', array('space' => $space)))); }
public function edit($path) { // Detects mode if (!$path['id']) { // Creates a new facility location $location = DataCenterDBLocation::newFromValues(array('tense' => 'present', 'name' => DataCenterUI::message('default', 'new-type', DataCenterUI::message('type', 'location')))); // Sets 'do' specific parameters $formParameters = array('label' => 'add', 'success' => array('page' => 'facilities', 'type' => 'location'), 'type' => 'add'); $headingParameters = array('message' => 'adding-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets facility location from database $location = DataCenterDB::getLocation($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'facilities', 'type' => 'location', 'action' => 'view', 'id' => $path['id']), 'type' => 'edit'); $headingParameters = array('message' => 'editing-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Builds JavaScript that hooks the button into the geocoder $jsForm = 'document.form_save'; $jsOut = DataCenterJs::callFunction('addHandler', array("{$jsForm}.field_button_0", DataCenterJs::toScalar('click'), DataCenterJs::buildFunction(null, DataCenterJs::chain(array('dataCenter.renderer.getTarget' => DataCenterJs::toScalar('map'), 'showAddress' => array('document.form_save.field_region.value', DataCenterJs::toObject(array('latField' => "'{$jsForm}.field_latitude'", 'lngField' => "'{$jsForm}.field_longitude'")))))))); // Complete form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'facilities', 'type' => 'location'), 'row' => $location, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'region' => array('type' => 'string'), array('type' => 'button', 'label' => 'lookup'), 'latitude' => array('type' => 'string'), 'longitude' => array('type' => 'string')))); // Returns 2 columm layout with a form and a map widget return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('map', !$path['id'] ? array() : array('location' => $location)))) . DataCenterXml::script($jsOut); }
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; }
public function configure($path) { // Detects mode if (!$path['id']) { if (is_array($path['parameter']) && count($path['parameter']) >= 2 && $path['parameter'][0] == 'space') { // Gets space from database $space = DataCenterDB::getSpace($path['parameter'][1]); // Creates new component $plan = DataCenterDBPlan::newFromValues(array('space' => $path['parameter'][1], 'tense' => 'present', 'name' => $space->get('name'))); // Sets 'do' specific parameters $formParameters = array('label' => 'create', 'hidden' => array('space'), 'success' => array('page' => 'plans')); $headingParameters = array('message' => 'adding-type', 'type' => 'plan'); } else { throw new MWException('Invalid parameters. space,# expected.'); } } else { // Gets component from database $plan = DataCenterDB::getPlan($path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'plan', 'action' => 'view', 'id' => $path['id'])); $headingParameters = array('message' => 'configuring-type', 'type' => 'plan'); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'plan'), 'row' => $plan, 'fields' => array('tense' => array('type' => 'tense', 'disable' => !$path['id'] ? array('past') : array()), 'name' => array('type' => 'string'), 'note' => array('type' => 'text'))))))), DataCenterUI::renderWidget('plan', array('plan' => $plan)))); }
public function configure($path) { // Checks if... if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 3 && $path['parameter'][0] == 'rack') { $object = DataCenterDB::getAsset('object', $path['parameter'][2]); $model = $object->getModel(); $rackLink = DataCenterDB::getAssetLink($path['parameter'][1]); $rack = $rackLink->getAsset(); $plan = DataCenterDB::getPlan($rackLink->get('plan')); $objectLink = DataCenterDBAssetLink::newFromValues(array('name' => $model->get('kind'), 'plan' => $plan->getId(), 'parent_link' => $rackLink->getId(), 'asset_type' => 'object', 'asset_id' => $object->getId(), 'z' => 1, 'orientation' => 0)); // Sets action specific parameters $formParameters = array('label' => 'attach', 'hidden' => array('plan', 'parent_link', 'asset_type', 'asset_id'), 'success' => array('page' => 'plans', 'type' => $path['parameter'][0], 'action' => 'view', 'id' => $path['parameter'][1])); $headingParameters = array('message' => 'attaching-type', 'type' => 'object'); } else { // Gets asset from database $objectLink = DataCenterDB::getAssetLink($path['id']); // Gets object that object link links to $object = $objectLink->getAsset(); // Gets plan from database $plan = DataCenterDB::getPlan($objectLink->get('plan')); // Gets rack link object is linked to $rackLink = DataCenterDB::getAssetLink($objectLink->get('parent_link')); // Extracts rack from rack link $rack = $rackLink->getAsset(); // Sets action specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'object', 'action' => 'view', 'id' => $path['id'])); $headingParameters = array('message' => 'configuring-type', 'type' => 'object'); } // Builds javascript that references the renderable asset $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule'); $rackId = $rack->getId(); $rackModel = $rack->getModel(); $objectModel = $object->getModel(); $objectId = $object->getId(); $maxZ = $rackModel->get('units') - $objectModel->get('units') + 1; // Builds form parameters $formFields = array('name' => array('type' => 'string'), 'position' => array('type' => 'number', 'field' => 'z', 'min' => 1, 'max' => $maxZ, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectPosition' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false)), 'orientation' => array('type' => 'number', 'min' => 0, 'max' => 1, 'effect' => DataCenterJs::chain(array_merge($target, array('setObjectOrientation' => array(DataCenterJs::toScalar($rackId), DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'object'), 'row' => $objectLink, 'fields' => $formFields))))), DataCenterUI::renderWidget('plan', array('plan' => $plan, 'current-rack' => $rack->getId(), 'look-at-rack' => $rack->getId(), 'current-object' => $object->getId(), 'include' => !$path['id'] ? $objectLink : null)))); }
public function configure($path) { // Checks if... if (!$path['id'] && is_array($path['parameter']) && count($path['parameter']) >= 3 && $path['parameter'][0] == 'plan') { // Gets plan from database $plan = DataCenterDB::getPlan($path['parameter'][1]); // Creates new asset with default parameters $rack = DataCenterDB::getAsset('rack', $path['parameter'][2]); // Creates new asset link $rackLink = DataCenterDBAssetLink::newFromValues(array('name' => DataCenterUI::message('type', 'rack'), 'plan' => $plan->getId(), 'asset_type' => 'rack', 'asset_id' => $rack->getId(), 'x' => 1, 'y' => 1, 'orientation' => 0)); // Sets action specific parameters $formParameters = array('label' => 'attach', 'hidden' => array('plan', 'asset_type', 'asset_id'), 'success' => array('page' => 'plans', 'type' => 'plan', 'action' => 'view', 'id' => $path['parameter'][1])); $headingParameters = array('message' => 'attaching-type', 'type' => 'rack'); } else { // Gets asset from database $rackLink = DataCenterDB::getAssetLink($path['id']); // Gets rack that rack link links to $rack = $rackLink->getAsset(); // Gets plan from database $plan = DataCenterDB::getPlan($rackLink->get('plan')); // Sets action specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'plans', 'type' => 'rack', 'action' => 'view', 'id' => $path['id'])); $headingParameters = array('message' => 'configuring-type', 'type' => 'rack'); } // Gets parent asset from database $space = $plan->getSpace(); // Builds javascript that references the renderable asset $target = array('dataCenter.renderer.getTarget' => array(DataCenterJs::toScalar('plan')), 'getModule'); $objectId = $rack->getId(); // Builds form parameters $formParameters = array_merge($formParameters, array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'plans', 'type' => 'rack'), 'row' => $rackLink, 'fields' => array('name' => array('type' => 'string'), 'position' => array('fields' => array('x' => array('field' => 'x', 'min' => 1, 'max' => $space->get('width')), 'y' => array('field' => 'y', 'min' => 1, 'max' => $space->get('depth'))), 'type' => 'position', 'effect' => DataCenterJs::chain(array_merge($target, array('setRackPosition' => array(DataCenterJs::toScalar($objectId), '{this.x}.value', '{this.y}.value', DataCenterJs::toScalar(true)))), false), 'mode' => 'iso'), 'orientation' => array('type' => 'number', 'min' => 0, 'max' => 3, 'effect' => DataCenterJs::chain(array_merge($target, array('setRackOrientation' => array(DataCenterJs::toScalar($objectId), '{this}.value', DataCenterJs::toScalar(true)))), false))))); // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', $formParameters))), DataCenterUI::renderWidget('plan', array('plan' => $plan, 'zoom-from-rack' => $rack->getIdOrZero(), 'current-rack' => $rack->getId(), 'include' => $rackLink)))); }
public static function render(array $parameters) { global $wgUser; // Gets current path $path = DataCenterPage::getPath(); // Sets Defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins widget $xmlOutput = parent::begin($parameters['class']); if (isset($path['parameter']) && is_array($path['parameter']) && count($path['parameter']) >= 2) { $changes = array(DataCenterDB::getChange($path['parameter'][0]), DataCenterDB::getChange($path['parameter'][1])); if ($changes[0]->get('timestamp') > $changes[1]->get('timestamp')) { $changes = array_reverse($changes); } // Use blank user name if none is set foreach ($changes as $change) { if ($change->get('user') == 0) { $change->set('username', DataCenterUI::message('label', 'change-blank-user')); } } // Get states from serialized versions $states = array(unserialize($changes[0]->get('state')), unserialize($changes[1]->get('state'))); // Begins table $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']); // Restructures data $data = array(); foreach ($states as $i => $state) { foreach ($state as $group => $fields) { if (!isset($data[$group])) { $data[$group] = array(); } foreach ($fields as $field => $value) { if ($field !== 'id') { if (!isset($data[$group][$field])) { $data[$group][$field] = array(); } $data[$group][$field][$i] = $value; } } } } $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(), DataCenterXml::cell($changes[0]->get('username') . ' - ' . DataCenterUI::format($changes[0]->get('timestamp'), 'date')), DataCenterXml::cell($changes[1]->get('username') . ' - ' . DataCenterUI::format($changes[1]->get('timestamp'), 'date'))); // Loops over each field foreach ($data as $group => $fields) { if (count($fields) == 0) { continue; } $xmlOutput .= DataCenterXml::row(DataCenterXml::headingCell(array_merge(self::$defaultAttributes['heading'], array('colspan' => 3)), DataCenterUI::message('label', 'change-state-' . $group))); $even = true; foreach ($fields as $field => $values) { // Deals with incomplete data if (count($values) == 1) { if (!isset($values[0])) { $values[0] = null; } if (!isset($values[1])) { $values[1] = null; } } // Detects differnce $different = (string) $values[0] !== (string) $values[1]; $spanAttributes = array('class' => $different ? 'different' : 'same'); // Gets label name if ($group == 'row') { $label = DataCenterUI::message('field', strtr($field, '_', '-')); } elseif ($group == 'meta') { $metaField = DataCenterDB::getMetaField($field); $label = $metaField->get('name'); } $state = $even ? 'even' : 'odd'; // Adds row $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(array('class' => 'label'), $label), DataCenterXml::cell(array('class' => 'older-' . $state), DataCenterXml::span($spanAttributes, $values[0])), DataCenterXml::cell(array('class' => 'newer-' . $state), DataCenterXml::span($spanAttributes, $values[1]))); $even = !$even; } } // Ends table $xmlOutput .= DataCenterXml::close('table'); } else { // Gets history of component from database $changes = $parameters['component']->getChanges(array_merge_recursive(DataCenterDB::buildSort('meta', 'change', array('timestamp DESC')), DataCenterDB::buildRange($path))); // Gets number of changes fromd database $numChanges = $parameters['component']->numChanges(); // Use blank user name if none is set foreach ($changes as $change) { if ($change->get('user') == 0) { $change->set('username', DataCenterUI::message('label', 'change-blank-user')); } } // Builds form attributes $formAttributes = array('id' => 'form_history', 'name' => 'form_history', 'method' => 'post', 'action' => DataCenterXml::url($path)); // Begins form $xmlOutput .= DataCenterXml::open('form', $formAttributes); // Begins table $xmlOutput .= DataCenterXml::open('table', self::$defaultAttributes['table']); // Adds paging $xmlOutput .= DataCenterXml::row(DataCenterXml::cell(self::$defaultAttributes['paging'], parent::buildPaging($path, $numChanges))); // Adds headings $xmlOutput .= DataCenterXml::row(DataCenterXml::headingCell(), DataCenterXml::headingCell(), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'date')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'username')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'type')), DataCenterXml::headingCell(self::$defaultAttributes['heading'], DataCenterUI::message('field', 'note'))); foreach ($changes as $i => $change) { // Build row attributes $rowAttributes = array('class' => $i % 2 == 0 ? 'odd' : 'even'); // Build radio attributes $radio1Attributes = array('type' => 'radio', 'name' => 'meta[change1]', 'id' => 'field_change1_' . $change->getId(), 'value' => $change->getId()); if ($i == 0) { $radio1Attributes['checked'] = 'checked'; } $radio2Attributes = array('type' => 'radio', 'name' => 'meta[change2]', 'id' => 'field_change2_' . $change->getId(), 'value' => $change->getId()); if ($i == 1 || count($changes) == 1) { $radio2Attributes['checked'] = 'checked'; } $xmlOutput .= DataCenterXml::row($rowAttributes, DataCenterXml::cell(self::$defaultAttributes['radio'], DataCenterXml::tag('input', $radio1Attributes)), DataCenterXml::cell(self::$defaultAttributes['radio'], DataCenterXml::tag('input', $radio2Attributes)), DataCenterXml::cell(self::$defaultAttributes['field'], DataCenterUI::format($change->get('timestamp'), 'date')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('username')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('type')), DataCenterXml::cell(self::$defaultAttributes['field'], $change->get('note'))); } // Adds reset and submit button $xmlOutput .= DataCenterXML::row(DataCenterXml::cell(self::$defaultAttributes['buttons'], DataCenterXml::tag('input', array('type' => 'reset', 'name' => 'reset', 'class' => 'reset', 'value' => DataCenterUI::message('label', 'reset'))) . DataCenterXml::tag('input', array('type' => 'submit', 'name' => 'submit', 'class' => 'submit', 'value' => DataCenterUI::message('label', 'compare-changes'))))); // Adds do field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'do', 'value' => 'compareChanges')); // Adds token field $xmlOutput .= DataCenterXml::tag('input', array('type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken())); $xmlOutput .= DataCenterXml::close('table'); $xmlOutput .= DataCenterXml::close('form'); } // Ends widget $xmlOutput .= parent::end(); // Returns results return $xmlOutput; }
public function main($path) { $plans = DataCenterDB::getPlans(DataCenterDB::buildSort('meta', 'plan', array('space', 'tense DESC'))); $numPlans = DataCenterDB::numPlans(); return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', array('message' => 'plans')), DataCenterUI::renderWidget('table', array('rows' => $plans, 'num' => $numPlans, 'fields' => array('name', 'space' => array('field' => 'space_name'), 'tense' => array('format' => 'option')), 'link' => array('page' => 'plans', 'action' => 'view', 'type' => 'plan', 'id' => '#id'))))))); }
public function modify($path) { // Checks if the type is supported if (!isset(self::$options[$path['type']]['gallery'])) { // Returns error message return wfMsg('datacenter-error-invalid-data'); } // Detects mode if (!$path['id']) { // Creates new component $model = DataCenterDBModel::newFromType($path['type']); // Sets 'do' specific parameters $formParameters = array('label' => 'create', 'success' => array('page' => 'models', 'type' => $path['type']), 'type' => 'create'); $headingParameters = array('message' => 'creating-model-type', 'subject' => DataCenterUI::message('type', $path['type'])); } else { // Gets component from database $model = DataCenterDB::getModel($path['type'], $path['id']); // Sets 'do' specific parameters $formParameters = array('label' => 'save', 'hidden' => array('id'), 'success' => array('page' => 'models', 'type' => $path['type'], 'action' => 'view', 'id' => $path['id']), 'type' => 'modify'); $headingParameters = array('message' => 'modifying-model-type', 'subject' => DataCenterUI::message('type', $path['type'])); } // Returns 2 columm layout with a form and a scene return DataCenterUI::renderLayout('columns', array(DataCenterUI::renderLayout('rows', array(DataCenterUI::renderWidget('heading', $headingParameters), DataCenterUI::renderWidget('form', array_merge($formParameters, self::$options[$path['type']]['form'], array('do' => 'save', 'failure' => $path, 'action' => array('page' => 'models', 'type' => $path['type']), 'row' => $model))))), '[MODEL VIEWER]')); }
public static function render(array $parameters) { // Sets defaults $parameters = array_merge(self::$defaultParameters, $parameters); // Begins input $xmlOutput = parent::begin($parameters['class']); // Begins select $xmlOutput .= DataCenterXml::open('select', array('name' => $parameters['name'], 'id' => $parameters['id'], 'class' => 'list')); // Checks if rows were given if ($parameters['rows']) { // Loops over each row foreach ($parameters['rows'] as $row) { // Builds attributes for option $optionAttributes = array('value' => $row->getId()); // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, implode($row->get($parameters['labels']), $parameters['glue'])); } // Alternatively check if options were given } elseif ($parameters['options']) { // Loops over each option foreach ($parameters['options'] as $key => $value) { // Checks if option key was not given if (is_int($key)) { // Uses key as value $optionAttributes = array('value' => $key); // Uses value as label $optionLabel = $value; } else { // Uses value as value $optionAttributes = array('value' => $value); // Uses key as label $optionLabel = $key; } // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= DataCenterXml::tag('option', $optionAttributes, DataCenterUI::message('option', $optionLabel)); } // Alternatively check if an enum was given } elseif (isset($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field'])) { // Gets enum values from database $enum = DataCenterDB::getEnum($parameters['enum']['category'], $parameters['enum']['type'], $parameters['enum']['field']); // Loops over each name foreach ($enum as $name) { // Uses name as value $optionAttributes = array('value' => $name); // Uses name as label $optionLabel = $name; // Checks if option value matches input value if ($optionAttributes['value'] == $parameters['value']) { // Adds selected attribute to option $optionAttributes['selected'] = 'selected'; } // Adds option $xmlOutput .= Xml::element('option', $optionAttributes, DataCenterUI::message('option', $optionLabel)); } } // Ends select $xmlOutput .= DataCenterXml::close('select'); // Ends input $xmlOutput .= parent::end(); // Returns XML return $xmlOutput; }
public static function export(array $data) { global $wgOut; // Disables MediaWiki output $wgOut->disable(); // Gets current path $path = DataCenterPage::getPath(); // Gets time in a nice format $date = date('Y-m-d'); $fileName = DataCenterUI::message('datacenter') . ' - ' . DataCenterUI::message('label', 'export-type', DataCenterUI::message('type', $data['meta']['type']) . ' ' . DataCenterUI::message('category', $data['meta']['category'])) . ' - ' . $date . '.' . $data['meta']['format']; // Sets headers for downloading CSV file header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"{$fileName}\""); $rows = DataCenterDB::getRows('DataCenterDBRow', $data['meta']['category'], $data['meta']['type']); $useMeta = $data['meta']['include-meta'] == 1 && ($data['meta']['category'] == 'facility' && DataCenterDB::isFacilityType($data['meta']['type']) || $data['meta']['category'] == 'asset' && DataCenterDB::isAssetType($data['meta']['type']) || $data['meta']['category'] == 'model' && DataCenterDB::isModelType($data['meta']['type'])); if ($data['meta']['format'] == 'csv') { $metaFieldsTable = null; $lines = array(); $fieldNames = ''; $first = true; foreach ($rows as $row) { $line = ''; $fields = $row->get(); foreach ($fields as $field => $value) { $line .= self::exportValue($value); } if ($first) { foreach ($fields as $field => $value) { $fieldNames .= self::exportValue(DataCenterUI::message('field', $field)); } } if ($useMeta) { $component = DataCenterDBComponent::newFromClass('DataCenterDBComponent', $data['meta']['category'], $data['meta']['type'], $fields); if (!$metaFieldsTable) { $metaFields = $component->getMetaFields(); $metaFieldsTable = array(); foreach ($metaFields as $metaField) { $metaFieldsTable[] = $metaField->get('field'); } if ($first) { foreach ($metaFields as $metaField) { $fieldNames .= self::exportValue($metaField->get('name')); } } } $metaValues = $component->getMetaValues(); $metaValuesTable = array(); foreach ($metaValues as $metaValue) { $metaValuesTable[$metaValue->get('field')] = $metaValue->get('value'); } foreach ($metaFieldsTable as $metaField) { if (isset($metaValuesTable[$metaField])) { $line .= self::exportValue($metaValuesTable[$metaField]); } else { $line .= ','; } } } $lines[] = rtrim($line, ',') . "\r\n"; $first = false; } echo rtrim($fieldNames, ',') . "\r\n"; echo implode($lines); } }
/** * Gets structure of links */ public function getStructure(array $options = array()) { if (!$this->structure) { $links = DataCenterDB::getRows('DataCenterDBAssetLink', 'link', 'asset', array_merge_recursive($options, DataCenterDB::buildCondition('link', 'asset', 'plan', $this->getId()))); $this->structure = array(); foreach ($links as $link) { if ($link->get('parent_link') == null) { $link->buildStructure($links); $this->structure[] = $link; } } } return $this->structure; }