r46035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46034‎ | r46035 | r46036 >
Date:22:10, 22 January 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Created new widget for editing field links. Finished settings for fields.
Modified paths:
  • /trunk/extensions/DataCenter/Controllers/Settings.php (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.css (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.db.php (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.i18n.php (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.page.php (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.php (modified) (history)
  • /trunk/extensions/DataCenter/DataCenter.ui.php (modified) (history)
  • /trunk/extensions/DataCenter/UI/Widgets/Body.php (modified) (history)
  • /trunk/extensions/DataCenter/UI/Widgets/FieldLinks.php (added) (history)
  • /trunk/extensions/DataCenter/UI/Widgets/Form.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Overview.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Settings/Field.php (added) (history)
  • /trunk/extensions/DataCenter/Views/Settings/Meta.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/DataCenter/DataCenter.php
@@ -85,6 +85,7 @@
8686 'DataCenterWidgetBody' => $dir . 'UI/Widgets/Body.php',
8787 'DataCenterWidgetDetails' => $dir . 'UI/Widgets/Details.php',
8888 'DataCenterWidgetDifference' => $dir . 'UI/Widgets/Difference.php',
 89+ 'DataCenterWidgetFieldLinks' => $dir . 'UI/Widgets/FieldLinks.php',
8990 'DataCenterWidgetForm' => $dir . 'UI/Widgets/Form.php',
9091 'DataCenterWidgetGallery' => $dir . 'UI/Widgets/Gallery.php',
9192 'DataCenterWidgetHeading' => $dir . 'UI/Widgets/Heading.php',
@@ -101,7 +102,7 @@
102103 'DataCenterViewPlansPlan' => $dir . 'Views/Plans/Plan.php',
103104 'DataCenterViewPlansRack' => $dir . 'Views/Plans/Rack.php',
104105 // Views/Settings/*
105 - 'DataCenterViewSettingsMeta' => $dir . 'Views/Settings/Meta.php',
 106+ 'DataCenterViewSettingsField' => $dir . 'Views/Settings/Field.php',
106107 // Views/*
107108 'DataCenterViewAssets' => $dir . 'Views/Assets.php',
108109 'DataCenterViewFacilities' => $dir . 'Views/Facilities.php',
Index: trunk/extensions/DataCenter/DataCenter.css
@@ -88,7 +88,6 @@
8989 /*
9090 * Form Widget
9191 */
92 -
9392 .datacenter-ui div.widget-form {
9493 border: solid 1px silver;
9594 }
@@ -115,6 +114,26 @@
116115 background-color: #DDEEFF;
117116 }
118117
 118+/*
 119+ * FieldLinks Widget
 120+ */
 121+.datacenter-ui div.widget-fieldlinks form {
 122+ margin: 0px;
 123+ padding: 0px;
 124+}
 125+.datacenter-ui div.widget-fieldlinks input.reset {
 126+ margin-right: 10px;
 127+}
 128+div.datacenter-ui div.widget-fieldlinks tr td {
 129+ padding-top: 8px;
 130+ padding-bottom: 8px;
 131+ padding-left: 8px;
 132+ padding-right: 8px;
 133+}
 134+.datacenter-ui div.widget-fieldlinks input.reset {
 135+ margin-right: 10px;
 136+}
 137+
119138 /**
120139 * Heading Widget
121140 */
@@ -243,6 +262,29 @@
244263 }
245264
246265 /**
 266+ * FieldLinks Widget
 267+ */
 268+div.datacenter-ui div.widget-fieldlinks table {
 269+ background-color: white;
 270+ border: solid 1px #DDDDDD;
 271+ width: 100%;
 272+}
 273+div.datacenter-ui div.widget-fieldlinks th {
 274+ background-color: #DDDDDD;
 275+ color: #999999;
 276+ padding-top: 4px;
 277+ padding-bottom: 4px;
 278+ padding-left: 8px;
 279+ padding-right: 8px;
 280+}
 281+div.datacenter-ui div.widget-fieldlinks tr td {
 282+ padding-top: 4px;
 283+ padding-bottom: 4px;
 284+ padding-left: 8px;
 285+ padding-right: 8px;
 286+}
 287+
 288+/**
247289 * Model Widget
248290 */
249291 div.datacenter-ui div.widget-model table {
Index: trunk/extensions/DataCenter/DataCenter.db.php
@@ -1091,6 +1091,84 @@
10921092 return self::numRows( 'meta', 'change', $options );
10931093 }
10941094
 1095+ /**
 1096+ * Wraps self::getRows specializing...
 1097+ * - class as DataCenterDBMetaField
 1098+ * - category as meta
 1099+ * - type as field
 1100+ */
 1101+ public static function getMetaFields(
 1102+ array $options = array()
 1103+ ) {
 1104+ return self::getRows(
 1105+ 'DataCenterDBMetaField', 'meta', 'field', $options
 1106+ );
 1107+ }
 1108+
 1109+ /**
 1110+ * Wraps self::getRow specializing...
 1111+ * - class as DataCenterDBMetaFieldLink
 1112+ * - category as meta
 1113+ * - type as field
 1114+ */
 1115+ public static function getMetaField(
 1116+ $id
 1117+ ) {
 1118+ return self::getRow(
 1119+ 'DataCenterDBMetaField', 'meta', 'field', $id
 1120+ );
 1121+ }
 1122+
 1123+ /**
 1124+ * Wraps self::numRows specializing...
 1125+ * - category as meta
 1126+ * - type as field
 1127+ */
 1128+ public static function numMetaFields(
 1129+ array $options = array()
 1130+ ) {
 1131+ return self::numRows( 'meta', 'field', $options );
 1132+ }
 1133+
 1134+ /**
 1135+ * Wraps self::getRows specializing...
 1136+ * - class as DataCenterDBMetaValue
 1137+ * - category as meta
 1138+ * - type as value
 1139+ */
 1140+ public static function getMetaValues(
 1141+ array $options = array()
 1142+ ) {
 1143+ return self::getRows(
 1144+ 'DataCenterDBMetaValue', 'meta', 'value', $options
 1145+ );
 1146+ }
 1147+
 1148+ /**
 1149+ * Wraps self::getRow specializing...
 1150+ * - class as DataCenterDBMetaValueLink
 1151+ * - category as meta
 1152+ * - type as value
 1153+ */
 1154+ public static function getMetaValue(
 1155+ $id
 1156+ ) {
 1157+ return self::getRow(
 1158+ 'DataCenterDBMetaValue', 'meta', 'value', $id
 1159+ );
 1160+ }
 1161+
 1162+ /**
 1163+ * Wraps self::numRows specializing...
 1164+ * - category as meta
 1165+ * - type as value
 1166+ */
 1167+ public static function numMetaValues(
 1168+ array $options = array()
 1169+ ) {
 1170+ return self::numRows( 'meta', 'value', $options );
 1171+ }
 1172+
10951173 /* Option Builders */
10961174
10971175 /**
@@ -1899,6 +1977,52 @@
19001978 ) {
19011979 return parent::newFromClass( __CLASS__, 'link', 'field', $values );
19021980 }
 1981+
 1982+ /* Functions */
 1983+
 1984+ public function getValues() {
 1985+ return DataCenterDB::getMetaValues(
 1986+ array_merge_recursive(
 1987+ DataCenterDB::buildCondition(
 1988+ 'meta', 'value', 'field', $this->get( 'field' )
 1989+ ),
 1990+ DataCenterDB::buildCondition(
 1991+ 'meta',
 1992+ 'value',
 1993+ 'component_category',
 1994+ $this->get( 'component_category' )
 1995+ ),
 1996+ DataCenterDB::buildCondition(
 1997+ 'meta',
 1998+ 'value',
 1999+ 'component_type',
 2000+ $this->get( 'component_type' )
 2001+ )
 2002+ )
 2003+ );
 2004+ }
 2005+
 2006+ public function numValues() {
 2007+ return DataCenterDB::numMetaValues(
 2008+ array_merge_recursive(
 2009+ DataCenterDB::buildCondition(
 2010+ 'meta', 'value', 'field', $this->get( 'field' )
 2011+ ),
 2012+ DataCenterDB::buildCondition(
 2013+ 'meta',
 2014+ 'value',
 2015+ 'component_category',
 2016+ $this->get( 'component_category' )
 2017+ ),
 2018+ DataCenterDB::buildCondition(
 2019+ 'meta',
 2020+ 'value',
 2021+ 'component_type',
 2022+ $this->get( 'component_type' )
 2023+ )
 2024+ )
 2025+ );
 2026+ }
19032027 }
19042028
19052029 /* Facility Rows */
@@ -1994,6 +2118,37 @@
19952119 ) {
19962120 return parent::newFromClass( __CLASS__, 'meta', 'field', $values );
19972121 }
 2122+
 2123+ /* Functions */
 2124+
 2125+ public function getLinks(
 2126+ array $options = array()
 2127+ ) {
 2128+ return DataCenterDB::getMetaFieldLinks(
 2129+ array_merge_recursive(
 2130+ $options,
 2131+ DataCenterDB::buildCondition(
 2132+ 'link', 'field', 'field', $this->getId()
 2133+ )
 2134+ )
 2135+ );
 2136+ }
 2137+
 2138+ public function getValues() {
 2139+ return DataCenterDB::getMetaValues(
 2140+ DataCenterDB::buildCondition(
 2141+ 'meta', 'value', 'field', $this->getId()
 2142+ )
 2143+ );
 2144+ }
 2145+
 2146+ public function numValues() {
 2147+ return DataCenterDB::numMetaValues(
 2148+ DataCenterDB::buildCondition(
 2149+ 'meta', 'value', 'field', $this->getId()
 2150+ )
 2151+ );
 2152+ }
19982153 }
19992154
20002155 class DataCenterDBMetaValue extends DataCenterDBRow {
Index: trunk/extensions/DataCenter/Controllers/Settings.php
@@ -11,7 +11,7 @@
1212 /* Members */
1313
1414 public $types = array(
15 - 'meta' => array( 'page' => 'settings', 'type' => 'meta' ),
 15+ 'field' => array( 'page' => 'settings', 'type' => 'field' ),
1616 );
1717
1818 /* Functions */
@@ -20,21 +20,63 @@
2121 array $path
2222 ) {
2323 // Actions
 24+ if ( $path['id'] && $path['type'] == 'field' ) {
 25+ $this->actions['remove'] = array(
 26+ 'page' => 'settings',
 27+ 'type' => $path['type'],
 28+ 'action' => 'remove',
 29+ 'id' => $path['id']
 30+ );
 31+ $this->actions['configure'] = array(
 32+ 'page' => 'settings',
 33+ 'type' => $path['type'],
 34+ 'action' => 'configure',
 35+ 'id' => $path['id']
 36+ );
 37+ $this->actions['view'] = array(
 38+ 'page' => 'settings',
 39+ 'type' => $path['type'],
 40+ 'action' => 'view',
 41+ 'id' => $path['id']
 42+ );
 43+ }
2444 }
2545
26 - public function add(
 46+ public function save(
2747 array $data,
2848 $type
2949 ) {
30 - $setting = DataCenterMeta::newFromValues( $type, $data['row'] );
31 - return $setting->save();
 50+ switch ( $type ) {
 51+ case 'field':
 52+ $field = DataCenterDBMetaField::newFromValues( $data['row'] );
 53+ $field->save();
 54+ return true;
 55+ }
 56+ return false;
3257 }
3358
34 - public function edit(
 59+ public function remove(
3560 array $data,
3661 $type
3762 ) {
38 - $setting = DataCenterMeta::newFromValues( $type, $data['row'] );
39 - return $setting->save();
 63+ switch ( $type ) {
 64+ case 'field':
 65+ $field = DataCenterDBMetaField::newFromValues( $data['row'] );
 66+ $values = $field->getValues();
 67+ foreach ( $values as $value ) {
 68+ $value->delete();
 69+ }
 70+ $field->delete();
 71+ return true;
 72+ }
 73+ return false;
4074 }
 75+
 76+ public function saveFieldLinks(
 77+ array $data,
 78+ $type
 79+ ) {
 80+ DataCenterWidgetFieldLinks::saveFieldLinks( $data );
 81+ return true;
 82+ }
4183 }
\ No newline at end of file
Index: trunk/extensions/DataCenter/DataCenter.page.php
@@ -114,7 +114,7 @@
115115 'controller' => 'DataCenterControllerSettings',
116116 'view' => 'DataCenterViewSettings',
117117 'types' => array(
118 - 'meta' => 'DataCenterViewSettingsMeta',
 118+ 'field' => 'DataCenterViewSettingsField',
119119 ),
120120 'default' => 'meta'
121121 )
@@ -178,8 +178,14 @@
179179 }
180180
181181 private static function loadState() {
182 - // Load state from session
183 - self::$state = $_SESSION['DATA_CENTER_STATE'];
 182+ // Checks if state information is in the session
 183+ if ( isset( $_SESSION['DATA_CENTER_STATE'] ) ) {
 184+ // Load state from session
 185+ self::$state = $_SESSION['DATA_CENTER_STATE'];
 186+ } else {
 187+ // Use fallbacks for expected values where possible
 188+ self::$state['private']['last-page'] = $_SERVER['PHP_SELF'];
 189+ }
184190 }
185191
186192 private static function saveState() {
@@ -209,10 +215,6 @@
210216 }
211217
212218 public static function getRefererPath() {
213 - if ( !self::$state['private']['last-page'] ) {
214 - // Use this page as a fallback
215 - self::$state['private']['last-page'] = $_SERVER['PHP_SELF'];
216 - }
217219 return self::subToPath(
218220 self::urlToSub( self::$state['private']['last-page'] )
219221 );
Index: trunk/extensions/DataCenter/DataCenter.ui.php
@@ -754,6 +754,7 @@
755755 'body' => 'DataCenterWidgetBody',
756756 'details' => 'DataCenterWidgetDetails',
757757 'difference' => 'DataCenterWidgetDifference',
 758+ 'fieldlinks' => 'DataCenterWidgetFieldLinks',
758759 'form' => 'DataCenterWidgetForm',
759760 'gallery' => 'DataCenterWidgetGallery',
760761 'heading' => 'DataCenterWidgetHeading',
@@ -835,6 +836,9 @@
836837 case 'type':
837838 return self::message( 'type', $value );
838839 break;
 840+ case 'category':
 841+ return self::message( 'category', $value );
 842+ break;
839843 case 'side':
840844 return self::message( 'option', $value ? 'front' : 'back' );
841845 break;
Index: trunk/extensions/DataCenter/UI/Widgets/Body.php
@@ -32,6 +32,11 @@
3333 */
3434 'subject' => null,
3535 /**
 36+ * Name of type of component to inject as parameter for message
 37+ * @datatype string
 38+ */
 39+ 'type' => null,
 40+ /**
3641 * Text to display
3742 * @datatype string
3843 */
@@ -40,7 +45,7 @@
4146 * Style of box to display body in
4247 * @datatype string
4348 */
44 - 'type' => 'generic',
 49+ 'style' => 'generic',
4550 );
4651
4752 /* Functions */
@@ -56,7 +61,7 @@
5762 if (
5863 // Required parameters
5964 isset( $parameters['message'] ) &&
60 - // Required types
 65+ // Required styles
6166 is_scalar( $parameters['message'] ) &&
6267 // Required values
6368 ( $parameters['message'] !== null )
@@ -70,6 +75,14 @@
7176 $message = DataCenterUI::message(
7277 'body', $parameters['message'], $parameters['subject']
7378 );
 79+ // Checks if a type was given
 80+ } else if ( $parameters['type'] !== null ) {
 81+ // Uses type-based message
 82+ $message = DataCenterUI::message(
 83+ 'body',
 84+ $parameters['message'],
 85+ DataCenterUI::message( 'type', $parameters['type'] )
 86+ );
7487 } else {
7588 // Uses plain message
7689 $message = DataCenterUI::message(
@@ -78,21 +91,21 @@
7992 }
8093 // Returns body with message
8194 $xmlOutput .= DataCenterXml::div(
82 - array( 'class' => $parameters['type'] ),
 95+ array( 'class' => $parameters['style'] ),
8396 DataCenterXml::div( $message )
8497 );
8598 // Checks if text was given
8699 } else if (
87100 // Required parameters
88101 isset( $parameters['text'] ) &&
89 - // Required types
 102+ // Required styles
90103 is_scalar( $parameters['text'] ) &&
91104 // Required values
92105 ( $parameters['text'] !== null )
93106 ) {
94107 // Returns a body with text
95108 $xmlOutput .= DataCenterXml::div(
96 - array( 'class' => $parameters['type'] ),
 109+ array( 'class' => $parameters['style'] ),
97110 DataCenterXml::div( $parameters['text'] )
98111 );
99112 }
Index: trunk/extensions/DataCenter/UI/Widgets/Form.php
@@ -114,22 +114,23 @@
115115 * Default XML attributes for label cell
116116 */
117117 'label' => array(
 118+ 'class' => 'label',
118119 'align' => 'left',
119120 'nowrap' => 'nowrap',
120 - 'class' => 'label'
121121 ),
122122 /**
123123 * Default XML attributes for field cell
124124 */
125125 'field' => array(
 126+ 'class' => 'field',
126127 'width' => '200',
127128 'align' => 'left',
128 - 'class' => 'field'
129129 ),
130130 /**
131131 * Default XML attributes for submit button cell
132132 */
133 - 'submit' => array(
 133+ 'buttons' => array(
 134+ 'class' => 'buttons',
134135 'align' => 'right',
135136 'colspan' => 2
136137 ),
@@ -174,9 +175,7 @@
175176 ),
176177 );
177178 // Begins form
178 - $xmlOutput .= DataCenterXml::open(
179 - 'form', $formAttributes
180 - );
 179+ $xmlOutput .= DataCenterXml::open( 'form', $formAttributes );
181180 // Inserts content before fields
182181 $xmlOutput .= $parameters['insert'];
183182 // Begins table
@@ -381,7 +380,7 @@
382381 // Adds cancel and submit button
383382 $xmlOutput .= DataCenterXML::row(
384383 DataCenterXml::cell(
385 - self::$defaultAttributes['submit'],
 384+ self::$defaultAttributes['buttons'],
386385 DataCenterXml::tag(
387386 'input',
388387 array(
Index: trunk/extensions/DataCenter/UI/Widgets/FieldLinks.php
@@ -0,0 +1,321 @@
 2+<?php
 3+
 4+/**
 5+ * UI Class for DataCenter extension
 6+ *
 7+ * @file
 8+ * @ingroup Extensions
 9+ */
 10+
 11+class DataCenterWidgetFieldLinks extends DataCenterWidget {
 12+
 13+ /* Private Static Members */
 14+
 15+ private static $defaultParameters = array(
 16+ /**
 17+ * XML ID attribute of widget
 18+ * @datatype string
 19+ */
 20+ 'id' => 'fieldlinks',
 21+ /**
 22+ * CSS class of widget
 23+ * @datatype string
 24+ */
 25+ 'class' => 'widget-fieldlinks',
 26+ /**
 27+ * Data Source
 28+ * @datatype DataCenterField
 29+ */
 30+ 'field' => null,
 31+ /**
 32+ * Current Path
 33+ * @datatype array
 34+ */
 35+ 'path' => null,
 36+ );
 37+
 38+ private static $targets = array(
 39+ 'facility' => array(
 40+ 'location',
 41+ 'space',
 42+ ),
 43+ 'asset' => array(
 44+ 'rack',
 45+ 'object',
 46+ ),
 47+ 'model' => array(
 48+ 'rack',
 49+ 'object',
 50+ 'port',
 51+ ),
 52+ );
 53+
 54+ private static $defaultAttributes = array(
 55+ /**
 56+ * Default XML attributes for table
 57+ */
 58+ 'table' => array(
 59+ 'width' => '100%',
 60+ 'cellpadding' => 5,
 61+ 'cellspacing' => 0,
 62+ 'border' => 0,
 63+ ),
 64+ /**
 65+ * Default XML attributes for heading cell
 66+ */
 67+ 'heading' => array(
 68+ 'align' => 'left',
 69+ 'colspan' => 3
 70+ ),
 71+ /**
 72+ * Default XML attributes for checkbox cell
 73+ */
 74+ 'checkbox' => array(
 75+ 'class' => 'checkbox',
 76+ 'width' => '10%',
 77+ ),
 78+ /**
 79+ * Default XML attributes for label cell
 80+ */
 81+ 'label' => array(
 82+ 'class' => 'label',
 83+ ),
 84+ /**
 85+ * Default XML attributes for label cell
 86+ */
 87+ 'uses' => array(
 88+ 'class' => 'uses',
 89+ ),
 90+ /**
 91+ * Default XML attributes for buttons cell
 92+ */
 93+ 'buttons' => array(
 94+ 'class' => 'buttons',
 95+ 'align' => 'right',
 96+ 'colspan' => 3
 97+ ),
 98+ );
 99+
 100+ /* Static Functions */
 101+
 102+ public static function render(
 103+ array $parameters
 104+ ) {
 105+ global $wgUser;
 106+ // Sets Defaults
 107+ $parameters = array_merge( self::$defaultParameters, $parameters );
 108+ // Begins widget
 109+ $xmlOutput = parent::begin( $parameters['class'] );
 110+ // Gets existing links from database
 111+ $metaFieldLinks = $parameters['field']->getLinks();
 112+ $existsTable = array();
 113+ foreach ( $metaFieldLinks as $metaFieldLink ) {
 114+ $key = implode(
 115+ '_',
 116+ $metaFieldLink->get(
 117+ array( 'component_category', 'component_type' )
 118+ )
 119+ );
 120+ $existsTable[$key] = $metaFieldLink;
 121+ }
 122+ // Builds form attributes
 123+ $formAttributes = array(
 124+ 'id' => 'form_fieldlinks',
 125+ 'name' => 'form_fieldlinks',
 126+ 'method' => 'post',
 127+ 'action' => DataCenterXml::url( $parameters['path'] ),
 128+ );
 129+ // Begins form
 130+ $xmlOutput .= DataCenterXml::open( 'form', $formAttributes );
 131+ // Begins table
 132+ $xmlOutput .= DataCenterXml::open(
 133+ 'table', self::$defaultAttributes['table']
 134+ );
 135+ foreach ( self::$targets as $category => $types ) {
 136+ $xmlOutput .= DataCenterXml::row(
 137+ DataCenterXml::headingCell(
 138+ self::$defaultAttributes['heading'],
 139+ DataCenterUI::message( 'category', $category )
 140+ )
 141+ );
 142+ foreach ( $types as $type ) {
 143+ $name = $category . '_' . $type;
 144+ $checkboxAttributes = array(
 145+ 'type' => 'checkbox',
 146+ 'name' => "meta[{$name}]",
 147+ 'id' => "field_{$name}",
 148+ 'value' => 1,
 149+ );
 150+ $count = 0;
 151+ if ( isset( $existsTable[$name] ) ) {
 152+ $checkboxAttributes['checked'] = 'checked';
 153+ $count = $existsTable[$name]->numValues();
 154+ if ( $count > 0 ) {
 155+ $checkboxAttributes['disabled'] = 'true';
 156+ $checkboxAttributes['name'] = "locked[{$name}]";
 157+ $xmlOutput .= DataCenterXml::tag(
 158+ 'input',
 159+ array(
 160+ 'type' => 'hidden',
 161+ 'name' => "meta[{$name}]",
 162+ 'value' => 1,
 163+ )
 164+ );
 165+ }
 166+ }
 167+ $xmlOutput .= DataCenterXml::row(
 168+ DataCenterXml::cell(
 169+ self::$defaultAttributes['checkbox'],
 170+ DataCenterXml::tag( 'input', $checkboxAttributes )
 171+ ),
 172+ DataCenterXml::cell(
 173+ self::$defaultAttributes['label'],
 174+ DataCenterXml::tag(
 175+ 'label',
 176+ array( 'for' => "field_{$name}" ),
 177+ DataCenterUI::message( 'type', $type )
 178+ )
 179+ ),
 180+ DataCenterXml::cell(
 181+ self::$defaultAttributes['uses'],
 182+ $count > 0 ?
 183+ DataCenterUI::message( 'label', 'num-uses', $count ) :
 184+ ''
 185+ )
 186+ );
 187+ }
 188+ }
 189+ // Adds reset and submit button
 190+ $xmlOutput .= DataCenterXML::row(
 191+ DataCenterXml::cell(
 192+ self::$defaultAttributes['buttons'],
 193+ DataCenterXml::tag(
 194+ 'input',
 195+ array(
 196+ 'type' => 'reset',
 197+ 'name' => 'reset',
 198+ 'class' => 'reset',
 199+ 'value' => DataCenterUI::message( 'label', 'reset' ),
 200+ )
 201+ ) .
 202+ DataCenterXml::tag(
 203+ 'input',
 204+ array(
 205+ 'type' => 'submit',
 206+ 'name' => 'submit',
 207+ 'class' => 'submit',
 208+ 'value' => DataCenterUI::message( 'label', 'save' ),
 209+ )
 210+ )
 211+ )
 212+ );
 213+ $xmlOutput .= DataCenterXml::close( 'table' );
 214+ // Adds row fields
 215+ $xmlOutput .= DataCenterXml::tag(
 216+ 'input', array(
 217+ 'type' => 'hidden',
 218+ 'name' => 'row[id]',
 219+ 'value' => $parameters['field']->getId(),
 220+ )
 221+ );
 222+ // Adds do field
 223+ $xmlOutput .= DataCenterXml::tag(
 224+ 'input', array(
 225+ 'type' => 'hidden',
 226+ 'name' => 'do',
 227+ 'value' => 'saveFieldLinks'
 228+ )
 229+ );
 230+ // Adds token field
 231+ $xmlOutput .= DataCenterXml::tag(
 232+ 'input', array(
 233+ 'type' => 'hidden',
 234+ 'name' => 'token',
 235+ 'value' => $wgUser->editToken()
 236+ )
 237+ );
 238+ // Adds success field
 239+ $xmlOutput .= DataCenterXml::tag(
 240+ 'input',
 241+ array(
 242+ 'type' => 'hidden',
 243+ 'name' => 'success',
 244+ 'value' => DataCenterXml::url( $parameters['path'] )
 245+ )
 246+ );
 247+ // Adds failure field
 248+ $xmlOutput .= DataCenterXml::tag(
 249+ 'input',
 250+ array(
 251+ 'type' => 'hidden',
 252+ 'name' => 'failure',
 253+ 'value' => DataCenterXml::url( $parameters['path'] )
 254+ )
 255+ );
 256+ // Adds canellation field
 257+ $xmlOutput .= DataCenterXml::tag(
 258+ 'input',
 259+ array(
 260+ 'type' => 'hidden',
 261+ 'name' => 'cancellation',
 262+ 'value' => DataCenterXml::url( $parameters['path'] )
 263+ )
 264+ );
 265+ $xmlOutput .= DataCenterXml::close( 'form' );
 266+ // Ends widget
 267+ $xmlOutput .= parent::end();
 268+ // Returns results
 269+ return $xmlOutput;
 270+ }
 271+
 272+ public function saveFieldLinks(
 273+ array $data
 274+ ) {
 275+ $metaField = DataCenterDBMetaField::newFromValues( $data['row'] );
 276+ $metaFieldLinks = $metaField->getLinks();
 277+ // Build table of links that do exist
 278+ $doesExistTable = array();
 279+ foreach ( $metaFieldLinks as $metaFieldLink ) {
 280+ $key = implode(
 281+ '_',
 282+ $metaFieldLink->get(
 283+ array( 'component_category', 'component_type' )
 284+ )
 285+ );
 286+ $doesExistTable[$key] = $metaFieldLink;
 287+ }
 288+ // Build table of links that should exist
 289+ $shouldExistTable = array();
 290+ foreach ( $data['meta'] as $key => $value ) {
 291+ list( $category, $type ) = explode( '_', $key );
 292+ $shouldExistTable[$category . '_' . $type] = true;
 293+ }
 294+ // Solve the difference
 295+ foreach ( self::$targets as $category => $types ) {
 296+ foreach ( $types as $type ) {
 297+ $key = $category . '_' . $type;
 298+ if (
 299+ isset( $shouldExistTable[$key] ) &&
 300+ !isset( $doesExistTable[$key] )
 301+ ) {
 302+ // Insert new
 303+ $metaFieldLink = DataCenterDBMetaFieldLink::newFromValues(
 304+ array(
 305+ 'field' => $metaField->getId(),
 306+ 'component_category' => $category,
 307+ 'component_type' => $type,
 308+ )
 309+ );
 310+ $metaFieldLink->insert();
 311+ } else if (
 312+ !isset( $shouldExistTable[$key] ) &&
 313+ isset( $doesExistTable[$key] ) &&
 314+ ( $doesExistTable[$key]->numValues() == 0 )
 315+ ) {
 316+ // Remove existing
 317+ $doesExistTable[$key]->delete();
 318+ }
 319+ }
 320+ }
 321+ }
 322+}
\ No newline at end of file
Index: trunk/extensions/DataCenter/Views/Settings/Meta.php
@@ -1,151 +0,0 @@
2 -<?php
3 -/**
4 - * Connections UI Class for DataCenter extension
5 - *
6 - * @file
7 - * @ingroup Extensions
8 - */
9 -
10 -class DataCenterViewSettingsMeta extends DataCenterView {
11 -
12 - /* Private Static Members */
13 -
14 - private static $componentTypes = array(
15 - 'facility' => array(
16 - 'location',
17 - 'space',
18 - ),
19 - 'asset' => array(
20 - 'rack',
21 - 'object',
22 - ),
23 - 'model' => array(
24 - 'rack',
25 - 'object',
26 - 'port',
27 - ),
28 - );
29 -
30 - /* Functions */
31 -
32 - public function main(
33 - $path
34 - ) {
35 - /*
36 - $tables = array();
37 - foreach ( $types as $type => $label ) {
38 - // Gets all components from database
39 - $fields = DataCenterDB::getMetaFields(
40 - DataCenterDB::buildCondition(
41 - 'meta', 'field', 'asset_type', $type
42 - )
43 - );
44 - // Adds table to list of tables
45 - $tables[$label] = DataCenterUI::renderWidget(
46 - 'table',
47 - array(
48 - 'heading' => array( 'message' => 'fields' ),
49 - 'rows' => $fields,
50 - 'fields' => array(
51 - 'name', 'format' => array( 'format' => 'option' )
52 - ),
53 - 'link' => array(
54 - 'page' => 'settings',
55 - 'type' => 'field',
56 - 'id' => '#id',
57 - 'action' => 'view',
58 - ),
59 - 'actions' => array(
60 - 'links' => array(
61 - array(
62 - 'page' => 'settings',
63 - 'type' => 'field',
64 - 'action' => 'add',
65 - 'parameter' => $type,
66 - ),
67 - ),
68 - ),
69 - )
70 - );
71 - }
72 - // Returns tabbed layout with tables of meta fields for each model type
73 - return DataCenterUI::renderLayout( 'tabs', $tables );
74 - */
75 - return '[LIST OF META FIELDS]';
76 - }
77 -
78 - public function add(
79 - $path
80 - ) {
81 - return $this->edit( $path );
82 - }
83 -
84 - public function edit(
85 - $path
86 - ) {
87 - // Detects mode
88 - if ( !$path['id'] ) {
89 - // Creates new component
90 - $field = DataCenterMeta::newFromValues(
91 - 'field', array( 'asset_type' => $path['parameter'] )
92 - );
93 - // Sets 'do' specific parameters
94 - $formParameters = array(
95 - 'do' => 'add',
96 - 'label' => 'add',
97 - 'hidden' => array( 'asset_type' ),
98 - 'success' => array(
99 - 'page' => 'settings',
100 - 'type' => 'meta'
101 - ),
102 - );
103 - } else {
104 - // Gets component from database
105 - $field = DataCenterDB::getMetaField( $path['id'] );
106 - // Sets 'do' specific parameters
107 - $formParameters = array(
108 - 'do' => 'edit',
109 - 'label' => 'save',
110 - 'hidden' => array( 'id', 'asset_type' ),
111 - 'success' => array(
112 - 'page' => 'settings',
113 - 'type' => 'meta',
114 - 'action' => 'view',
115 - 'id' => $path['id'],
116 - ),
117 - );
118 - }
119 - // Returns 2 columm layout with a form and a scene
120 - return DataCenterUI::renderLayout(
121 - 'columns',
122 - array(
123 - DataCenterUI::renderWidget(
124 - 'form',
125 - array_merge(
126 - $formParameters,
127 - array(
128 - 'failure' => $path,
129 - 'action' => array(
130 - 'page' => 'settings',
131 - 'type' => 'meta'
132 - ),
133 - 'row' => $field,
134 - 'fields' => array(
135 - 'name' => array( 'type' => 'string' ),
136 - 'format' => array(
137 - 'type' => 'list',
138 - 'enum' => array(
139 - 'category' => 'meta',
140 - 'type' => 'field',
141 - 'field' => 'format',
142 - ),
143 - ),
144 - ),
145 - )
146 - )
147 - ),
148 - '[MODEL VIEWER]',
149 - )
150 - );
151 - }
152 -}
\ No newline at end of file
Index: trunk/extensions/DataCenter/Views/Settings/Field.php
@@ -0,0 +1,271 @@
 2+<?php
 3+/**
 4+ * Connections UI Class for DataCenter extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class DataCenterViewSettingsField extends DataCenterView {
 11+
 12+ /* Functions */
 13+
 14+ public function main(
 15+ $path
 16+ ) {
 17+ $metaFields = DataCenterDB::getMetaFields();
 18+ return DataCenterUI::renderLayout(
 19+ 'columns',
 20+ array(
 21+ DataCenterUI::renderLayout(
 22+ 'rows',
 23+ array(
 24+ DataCenterUI::renderWidget(
 25+ 'heading', array( 'message' => 'fields' )
 26+ ),
 27+ DataCenterUI::renderWidget(
 28+ 'table',
 29+ array(
 30+ 'rows' => $metaFields,
 31+ 'fields' => array(
 32+ 'name',
 33+ 'format' => array( 'format' => 'option' )
 34+ ),
 35+ 'link' => array(
 36+ 'page' => 'settings',
 37+ 'type' => 'field',
 38+ 'action' => 'view',
 39+ 'id' => '#id',
 40+ )
 41+ )
 42+ ),
 43+ DataCenterUI::renderWidget(
 44+ 'actions',
 45+ array(
 46+ 'links' => array(
 47+ array(
 48+ 'page' => 'settings',
 49+ 'type' => 'field',
 50+ 'action' => 'add'
 51+ )
 52+ ),
 53+ )
 54+ ),
 55+ )
 56+ ),
 57+ )
 58+ );
 59+ }
 60+
 61+ public function view(
 62+ $path
 63+ ) {
 64+ $metaField = DataCenterDB::getMetaField( $path['id'] );
 65+ return DataCenterUI::renderLayout(
 66+ 'columns',
 67+ array(
 68+ DataCenterUI::renderLayout(
 69+ 'rows',
 70+ array(
 71+ DataCenterUI::renderWidget(
 72+ 'heading', array( 'message' => 'field' )
 73+ ),
 74+ DataCenterUI::renderWidget(
 75+ 'details',
 76+ array(
 77+ 'row' => $metaField,
 78+ 'fields' => array(
 79+ 'name',
 80+ 'format' => array( 'format' => 'option' )
 81+ )
 82+ )
 83+ ),
 84+ )
 85+ ),
 86+ DataCenterUI::renderLayout(
 87+ 'rows',
 88+ array(
 89+ DataCenterUI::renderWidget(
 90+ 'heading',
 91+ array( 'message' => 'applied-components' )
 92+ ),
 93+ DataCenterUI::renderWidget(
 94+ 'fieldlinks',
 95+ array(
 96+ 'field' => $metaField,
 97+ 'path' => $path,
 98+ )
 99+ ),
 100+ )
 101+ ),
 102+ )
 103+ );
 104+ }
 105+
 106+ public function remove(
 107+ $path
 108+ ) {
 109+ $metaField = DataCenterDB::getMetaField( $path['id'] );
 110+ $metaFieldLinks = $metaField->getLinks();
 111+ foreach ( $metaFieldLinks as $metaFieldLink ) {
 112+ $metaFieldLink->set( 'uses', $metaFieldLink->numValues() );
 113+ }
 114+ // Returns 2 columm layout with a form and a scene
 115+ return DataCenterUI::renderLayout(
 116+ 'columns',
 117+ array(
 118+ DataCenterUI::renderLayout(
 119+ 'rows',
 120+ array(
 121+ DataCenterUI::renderWidget(
 122+ 'heading',
 123+ array(
 124+ 'message' => 'remove-type',
 125+ 'type' => 'field'
 126+ )
 127+ ),
 128+ DataCenterUI::renderWidget(
 129+ 'body',
 130+ array(
 131+ 'message' => 'notice-removing-field',
 132+ 'style' => 'notice',
 133+ )
 134+ ),
 135+ DataCenterUI::renderWidget(
 136+ 'table',
 137+ array(
 138+ 'rows' => $metaFieldLinks,
 139+ 'fields' => array(
 140+ 'category' => array(
 141+ 'field' => 'component_category',
 142+ 'format' => 'category'
 143+ ),
 144+ 'type' => array(
 145+ 'field' => 'component_type',
 146+ 'format' => 'type'
 147+ ),
 148+ 'uses'
 149+ )
 150+ )
 151+ ),
 152+ DataCenterUI::renderWidget(
 153+ 'form',
 154+ array(
 155+ 'do' => 'remove',
 156+ 'label' => 'remove',
 157+ 'hidden' => array( 'id' ),
 158+ 'success' => array(
 159+ 'page' => 'settings',
 160+ 'type' => 'field',
 161+ ),
 162+ 'failure' => $path,
 163+ 'cancellation' => array(
 164+ 'page' => 'settings',
 165+ 'type' => 'field',
 166+ 'action' => 'view',
 167+ 'id' => $path['id'],
 168+ ),
 169+ 'row' => $metaField,
 170+ 'action' => array(
 171+ 'page' => 'settings',
 172+ 'type' => 'field'
 173+ ),
 174+ 'fields' => array()
 175+ )
 176+ )
 177+ )
 178+ ),
 179+ '&nbsp;'
 180+ )
 181+ );
 182+ }
 183+
 184+ public function add(
 185+ $path
 186+ ) {
 187+ return $this->configure( $path );
 188+ }
 189+
 190+ public function configure(
 191+ $path
 192+ ) {
 193+ // Detects mode
 194+ if ( !$path['id'] ) {
 195+ // Creates new component
 196+ $field = DataCenterDBMetaField::newFromValues();
 197+ // Sets 'do' specific parameters
 198+ $formParameters = array(
 199+ 'label' => 'add',
 200+ 'success' => array(
 201+ 'page' => 'settings',
 202+ 'type' => 'field'
 203+ ),
 204+ );
 205+ } else {
 206+ // Gets component from database
 207+ $field = DataCenterDB::getMetaField( $path['id'] );
 208+ // Sets 'do' specific parameters
 209+ $formParameters = array(
 210+ 'label' => 'save',
 211+ 'hidden' => array( 'id' ),
 212+ 'success' => array(
 213+ 'page' => 'settings',
 214+ 'type' => 'field',
 215+ 'action' => 'view',
 216+ 'id' => $path['id'],
 217+ ),
 218+ );
 219+ }
 220+ // Returns 2 columm layout with a form and a scene
 221+ return DataCenterUI::renderLayout(
 222+ 'columns',
 223+ array(
 224+ DataCenterUI::renderLayout(
 225+ 'rows',
 226+ array(
 227+ DataCenterUI::renderWidget(
 228+ 'heading',
 229+ array(
 230+ 'message' => 'configuring-type',
 231+ 'type' => 'field',
 232+ )
 233+ ),
 234+ DataCenterUI::renderWidget(
 235+ 'body',
 236+ array(
 237+ 'message' => 'important-configuring-field',
 238+ 'style' => 'important',
 239+ )
 240+ ),
 241+ DataCenterUI::renderWidget(
 242+ 'form',
 243+ array_merge(
 244+ $formParameters,
 245+ array(
 246+ 'do' => 'save',
 247+ 'failure' => $path,
 248+ 'action' => array(
 249+ 'page' => 'settings', 'type' => 'field'
 250+ ),
 251+ 'row' => $field,
 252+ 'fields' => array(
 253+ 'name' => array( 'type' => 'string' ),
 254+ 'format' => array(
 255+ 'type' => 'list',
 256+ 'enum' => array(
 257+ 'category' => 'meta',
 258+ 'type' => 'field',
 259+ 'field' => 'format',
 260+ ),
 261+ ),
 262+ ),
 263+ )
 264+ )
 265+ ),
 266+ )
 267+ ),
 268+ '&nbsp;'
 269+ )
 270+ );
 271+ }
 272+}
\ No newline at end of file
Property changes on: trunk/extensions/DataCenter/Views/Settings/Field.php
___________________________________________________________________
Name: svn:mergeinfo
1273 +
Name: svn:eol-style
2274 + native
Index: trunk/extensions/DataCenter/Views/Overview.php
@@ -22,8 +22,8 @@
2323 DataCenterUI::renderWidget(
2424 'body',
2525 array(
26 - 'message' => 'welcome',
27 - 'type' => 'important'
 26+ 'message' => 'important-welcome',
 27+ 'style' => 'important'
2828 )
2929 )
3030 )
Index: trunk/extensions/DataCenter/DataCenter.i18n.php
@@ -30,9 +30,15 @@
3131 'datacenter-ui-type-rack' => 'Rack',
3232 'datacenter-ui-type-object' => 'Object',
3333 'datacenter-ui-type-port' => 'Port',
34 - 'datacenter-ui-type-meta' => 'Meta',
3534 'datacenter-ui-type-model' => 'Model',
3635 'datacenter-ui-type-attachment' => 'Attachment',
 36+ 'datacenter-ui-type-field' => 'Field',
 37+ // Categories
 38+ 'datacenter-ui-category-facility' => 'Facility',
 39+ 'datacenter-ui-category-asset' => 'Asset',
 40+ 'datacenter-ui-category-model' => 'Model',
 41+ 'datacenter-ui-category-link' => 'Link',
 42+ 'datacenter-ui-category-meta' => 'Meta',
3743 // Actions
3844 'datacenter-ui-action-configure' => 'Configure',
3945 'datacenter-ui-action-edit' => 'Edit',
@@ -49,6 +55,7 @@
5056 'datacenter-ui-action-create-type' => 'Create $1',
5157 'datacenter-ui-action-design-type' => 'Design and Deploy $1',
5258 'datacenter-ui-action-select-type' => 'Select and Attach $1',
 59+ 'datacenter-ui-action-apply-type' => 'Apply $1',
5360 'datacenter-ui-action-history' => 'History',
5461 // Options
5562 'datacenter-ui-option-front' => 'Front',
@@ -74,6 +81,11 @@
7582 'datacenter-ui-option-future' => 'Future',
7683 'datacenter-ui-option-true' => 'True',
7784 'datacenter-ui-option-false' => 'False',
 85+ 'datacenter-ui-option-boolean' => 'Boolean (yes/no)',
 86+ 'datacenter-ui-option-string' => 'String (single-link)',
 87+ 'datacenter-ui-option-text' => 'Text (multi-line)',
 88+ 'datacenter-ui-option-number' => 'Number',
 89+ 'datacenter-ui-option-tag' => 'Tag',
7890 // Errors
7991 'datacenter-ui-error-insufficient-data' => 'You have provided insufficient data',
8092 'datacenter-ui-error-invalid-data' => 'You have provided invalid data',
@@ -129,7 +141,9 @@
130142 'datacenter-ui-field-manufacturer' => 'Manufacturer',
131143 'datacenter-ui-field-tense' => 'Tense',
132144 'datacenter-ui-field-change-summary' => 'Change Summary',
 145+ 'datacenter-ui-field-uses' => 'Uses',
133146 // Label
 147+ 'datacenter-ui-label-reset' => 'Reset',
134148 'datacenter-ui-label-cancel' => 'Cancel',
135149 'datacenter-ui-label-remove' => 'Remove',
136150 'datacenter-ui-label-save' => 'Save',
@@ -140,7 +154,8 @@
141155 'datacenter-ui-label-add' => 'Add',
142156 'datacenter-ui-label-add-type' => 'Add $1',
143157 'datacenter-ui-label-browse-by' => 'Browse by:',
144 - 'datacenter-ui-label-num-spaces' => '$1 {{PLURAL:$1|Space|Spaces}}',
 158+ 'datacenter-ui-label-num-spaces' => '$1 {{PLURAL:$1|Spaces|Space}}',
 159+ 'datacenter-ui-label-num-uses' => '$1 {{PLURAL:$1|uses|use}}',
145160 'datacenter-ui-label-degrees-value' => '$1&deg;',
146161 // Defaults
147162 'datacenter-ui-default-new-type' => 'New $1',
@@ -151,6 +166,8 @@
152167 'datacenter-ui-heading-spaces' => 'Spaces',
153168 'datacenter-ui-heading-racks' => 'Racks',
154169 'datacenter-ui-heading-objects' => 'Objects',
 170+ 'datacenter-ui-heading-fields' => 'Fields',
 171+ 'datacenter-ui-heading-applied-components' => 'Applied Components',
155172 // Information Headings
156173 'datacenter-ui-heading-details' => 'Details',
157174 'datacenter-ui-heading-model-attachments' => 'Model Attachments',
@@ -161,6 +178,7 @@
162179 'datacenter-ui-heading-location' => 'Location',
163180 'datacenter-ui-heading-space' => 'Space',
164181 'datacenter-ui-heading-configuration' => 'Configuration',
 182+ 'datacenter-ui-heading-field' => 'Field',
165183 // Type-based Headings
166184 'datacenter-ui-heading-history-type' => '$1 History',
167185 'datacenter-ui-heading-remove-type' => 'Remove $1?',
@@ -179,9 +197,11 @@
180198 'datacenter-ui-heading-attaching-type' => 'Attaching $1',
181199 'datacenter-ui-heading-configuring-type' => 'Configuring $1',
182200 // Bodies
183 - 'datacenter-ui-body-confirm-remove-type' => 'Removing this $1 will result in the removal of the following links and cannot be recovered from. Do you want to continue with the removal?',
184 - 'datacenter-ui-body-invalid-request' => 'You have requested a page with an invalid path.',
185 - 'datacenter-ui-body-welcome' => 'Welcome to the beta-testing of DataCenter. Please poke around and give feedback Trevor Parscal. If you are going to help out, take a look at the media wiki extension page for DataCenter which has a list of feature priorities.',
 201+ 'datacenter-ui-body-notice-removing-type' => 'Removing this $1 will result in the removal of the following links and cannot be recovered from. Do you want to continue with the removal?',
 202+ 'datacenter-ui-body-notice-removing-field' => 'Removing this field will result in the removal of the following links and all data associated with them and cannot be recovered from. Do you want to continue with the removal?',
 203+ 'datacenter-ui-body-important-configuring-field' => 'Changing the format of this field may cause related data to be interpreted incorectly, espcially when switching between textual, numeric and boolean formats.',
 204+ 'datacenter-ui-body-important-welcome' => 'Welcome to the beta-testing of DataCenter. Please poke around and give feedback Trevor Parscal. If you are going to help out, take a look at the media wiki extension page for DataCenter which has a list of feature priorities.',
 205+ 'datacenter-ui-body-error-invalid-request' => 'You have requested a page with an invalid path.',
186206 // Tabs
187207 'datacenter-ui-tab-racks' => 'Racks',
188208 'datacenter-ui-tab-details' => 'Details',

Status & tagging log