r45942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45941‎ | r45942 | r45943 >
Date:23:08, 20 January 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Added change history tracking and basic viewing for facilities, assets and models.
Modified paths:
  • /trunk/extensions/DataCenter/Controllers/Assets.php (modified) (history)
  • /trunk/extensions/DataCenter/Controllers/Facilities.php (modified) (history)
  • /trunk/extensions/DataCenter/Controllers/Models.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.sql (modified) (history)
  • /trunk/extensions/DataCenter/UI/Widgets/Difference.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Facilities.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Facilities/Location.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Facilities/Space.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/History.php (modified) (history)
  • /trunk/extensions/DataCenter/Views/Models.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DataCenter/DataCenter.css
@@ -412,20 +412,20 @@
413413 border: solid 1px silver;
414414 width: 100%;
415415 }
416 -div.datacenter-ui div.widget-difference td.field {
 416+div.datacenter-ui div.widget-difference td.label {
417417 width: 20%;
418418 padding-left: 8px;
419419 padding-right: 8px;
420420 color: gray;
421421 }
422 -div.datacenter-ui div.widget-difference td.value-a {
 422+div.datacenter-ui div.widget-difference td.previous {
423423 width: 40%;
424424 padding-left: 8px;
425425 padding-right: 8px;
426426 color: green;
427427 background-color: #DDFFDD;
428428 }
429 -div.datacenter-ui div.widget-difference td.value-b {
 429+div.datacenter-ui div.widget-difference td.current {
430430 width: 40%;
431431 padding-left: 8px;
432432 padding-right: 8px;
Index: trunk/extensions/DataCenter/DataCenter.db.php
@@ -1475,6 +1475,13 @@
14761476 }
14771477
14781478 /**
 1479+ * Determines whether a row is present in the database
 1480+ */
 1481+ public function exists() {
 1482+ return DataCenterDB::rowExists( $this );
 1483+ }
 1484+
 1485+ /**
14791486 * Automatically inserts or updates row
14801487 */
14811488 public function save() {
@@ -1514,9 +1521,12 @@
15151522 /**
15161523 * Gets changes that reference this object by category, type, and ID
15171524 */
1518 - public function getChanges() {
 1525+ public function getChanges(
 1526+ array $options = array()
 1527+ ) {
15191528 return DataCenterDB::getChanges(
15201529 array_merge_recursive(
 1530+ $options,
15211531 DataCenterDB::buildCondition(
15221532 'meta', 'change', 'component_category', $this->category
15231533 ),
@@ -1976,7 +1986,8 @@
19771987 $type = null,
19781988 $note = null
19791989 ) {
1980 - if ( !is_string( $type ) ) {
 1990+ global $wgUser;
 1991+ if ( $type !== null && !is_string( $type ) ) {
19811992 throw new MWException(
19821993 $type . ' is not a valid type of change'
19831994 );
@@ -1986,7 +1997,6 @@
19871998 $type . ' is not a valid change note'
19881999 );
19892000 }
1990 - global $wgUser;
19912001 return self::newFromValues(
19922002 array(
19932003 'timestamp' => wfTimestampNow(),
Index: trunk/extensions/DataCenter/Controllers/Facilities.php
@@ -49,14 +49,18 @@
5050 ) {
5151 switch ( $type ) {
5252 case 'location':
53 - $location = DataCenterDBLocation::newFromValues( $data );
54 - $location->save();
55 - return true;
 53+ $component = DataCenterDBLocation::newFromValues( $data );
 54+ break;
5655 case 'space':
57 - $space = DataCenterDBSpace::newFromValues( $data );
58 - $space->save();
59 - return true;
 56+ $component = DataCenterDBSpace::newFromValues( $data );
 57+ break;
6058 }
 59+ if ( isset( $component ) ) {
 60+ $component->save();
 61+ $change = DataCenterDBChange::newFromComponent( $component );
 62+ $change->save();
 63+ return true;
 64+ }
6165 return false;
6266 }
6367 }
\ No newline at end of file
Index: trunk/extensions/DataCenter/Controllers/Assets.php
@@ -47,9 +47,10 @@
4848 array $data,
4949 $type
5050 ) {
51 - $asset = DataCenterAsset::newFromType( $type, $data );
 51+ $asset = DataCenterDBAsset::newFromType( $type, $data );
5252 $asset->save();
 53+ $change = DataCenterDBChange::newFromComponent( $asset );
 54+ $change->save();
5355 return true;
5456 }
55 -
5657 }
\ No newline at end of file
Index: trunk/extensions/DataCenter/Controllers/Models.php
@@ -50,6 +50,8 @@
5151 ) {
5252 $model = DataCenterDBModel::newFromType( $type, $data );
5353 $model->save();
 54+ $change = DataCenterDBChange::newFromComponent( $model );
 55+ $change->save();
5456 return true;
5557 }
5658
Index: trunk/extensions/DataCenter/DataCenter.sql
@@ -199,8 +199,7 @@
200200 PRIMARY KEY (mta_pln_id)
201201 ) /*$wgDBTableOptions*/;
202202 --
 203+-- Table of changes made to targets (facilities, assets and models)
203204 DROP TABLE IF EXISTS dc_meta_changes;
204205 CREATE TABLE /*$wgDBPrefix*/dc_meta_changes (
205206 -- Unique ID of dc_meta_changes
@@ -390,8 +389,8 @@
391390 fcl_loc_longitude
392391 )
393392 VALUES
394 - ( 'present', 'PMTPA', 'Tampa, FL', 27.949036, -82.457306 ),
395 - ( 'present', 'SFO', 'San Francisco, CA', 37.782792, -122.394810 );
 393+ ( 'present', 'PMTPA', 'Tampa, FL', 27.98141, -82.451141 ),
 394+ ( 'present', 'SFO', 'San Francisco, CA', 37.775196, -122.419204 );
396395 --
397396 INSERT INTO dc_facility_spaces
398397 (
Index: trunk/extensions/DataCenter/UI/Widgets/Difference.php
@@ -31,11 +31,6 @@
3232 * @datatype DataCenterDBRow
3333 */
3434 'current' => null,
35 - /**
36 - * Fields to display
37 - * @datatype array
38 - */
39 - 'fields' => null,
4035 );
4136
4237 /* Functions */
@@ -51,12 +46,13 @@
5247 $xmlOutput .= DataCenterXml::open( 'table' );
5348 // Checks that an array of fields and valid rows were given
5449 if (
55 - is_array( $parameters['fields'] ) &&
56 - ( $parameters['previous'] instanceof DataCenterDBRow ) &&
57 - ( $parameters['current'] instanceof DataCenterDBRow )
 50+ is_array( $parameters['previous'] ) &&
 51+ is_array( $parameters['current'] )
5852 ) {
5953 // Loops over each field
60 - foreach ( $parameters['fields'] as $field ) {
 54+ foreach ( $parameters['current'] as $field => $value ) {
 55+ // Detects changed field
 56+ $different = ( $value !== $parameters['previous'][$field] );
6157 // Adds row
6258 $xmlOutput .= DataCenterXml::row(
6359 DataCenterXml::cell(
@@ -65,11 +61,21 @@
6662 ),
6763 DataCenterXml::cell(
6864 array( 'class' => 'previous' ),
69 - $parameters['previous']->get( $field )
 65+ DataCenterXml::span(
 66+ array(
 67+ 'class' => $different ? 'different' : 'same'
 68+ ),
 69+ $parameters['previous'][$field]
 70+ )
7071 ),
7172 DataCenterXml::cell(
7273 array( 'class' => 'current' ),
73 - $parameters['current']->get( $field )
 74+ DataCenterXml::span(
 75+ array(
 76+ 'class' => $different ? 'different' : 'same'
 77+ ),
 78+ $value
 79+ )
7480 )
7581 );
7682 }
Index: trunk/extensions/DataCenter/Views/Facilities.php
@@ -10,15 +10,4 @@
1111
1212 /* Functions */
1313
14 - public function main(
15 - $path
16 - ) {
17 - return DataCenterUI::renderLayout(
18 - 'columns',
19 - array(
20 - __CLASS__,
21 - __METHOD__
22 - )
23 - );
24 - }
2514 }
\ No newline at end of file
Index: trunk/extensions/DataCenter/Views/History.php
@@ -40,7 +40,8 @@
4141 'link' => array(
4242 'page' => 'history',
4343 'type' => 'change',
44 - 'action' => 'view'
 44+ 'action' => 'view',
 45+ 'id' => '#id',
4546 )
4647 )
4748 )
@@ -58,7 +59,7 @@
5960 }
6061 $change = DataCenterDB::getChange( $path['id'] );
6162 $component = DataCenterDB::getRow(
62 - 'DataCenterComponent',
 63+ 'DataCenterDBComponent',
6364 $change->get( 'component_category' ),
6465 $change->get( 'component_type' ),
6566 $change->get( 'component_id' )
@@ -66,13 +67,24 @@
6768 return DataCenterUI::renderLayout(
6869 'columns',
6970 array(
70 - DataCenterUI::renderWidget(
71 - 'difference',
 71+ DataCenterUI::renderLayout(
 72+ 'rows',
7273 array(
73 - 'row-a' => $component->get(),
74 - 'row-b' => unserialize( $change->get( 'state' ) )
 74+ DataCenterUI::renderWidget(
 75+ 'heading',
 76+ array( 'message' => 'difference' )
 77+ ),
 78+ DataCenterUI::renderWidget(
 79+ 'difference',
 80+ array(
 81+ 'current' => $component->get(),
 82+ 'previous' => unserialize(
 83+ $change->get( 'state' )
 84+ )
 85+ )
 86+ )
7587 )
76 - )
 88+ ),
7789 )
7890 );
7991 }
@@ -83,7 +95,11 @@
8496 $path,
8597 $component
8698 ) {
87 - $changes = $component->getChanges();
 99+ $changes = $component->getChanges(
 100+ DataCenterDB::buildSort(
 101+ 'meta', 'change', 'timestamp DESC'
 102+ )
 103+ );
88104 return DataCenterUI::renderWidget( 'table',
89105 array(
90106 'rows' => $changes,
@@ -99,7 +115,8 @@
100116 'link' => array(
101117 'page' => 'history',
102118 'type' => 'change',
103 - 'action' => 'view'
 119+ 'action' => 'view',
 120+ 'id' => '#id',
104121 )
105122 )
106123 );
Index: trunk/extensions/DataCenter/Views/Models.php
@@ -198,6 +198,18 @@
199199 );
200200 }
201201
 202+ public function history(
 203+ $path
 204+ ) {
 205+ $asset = DataCenterDB::getAsset( $path['type'], $path['id'] );
 206+ return DataCenterUI::renderLayout(
 207+ 'columns',
 208+ array(
 209+ DataCenterViewHistory::typeHistory( $path, $asset )
 210+ )
 211+ );
 212+ }
 213+
202214 public function view(
203215 $path
204216 ) {
Index: trunk/extensions/DataCenter/Views/Facilities/Space.php
@@ -73,6 +73,18 @@
7474 );
7575 }
7676
 77+ public function history(
 78+ $path
 79+ ) {
 80+ $asset = DataCenterDB::getSpace( $path['id'] );
 81+ return DataCenterUI::renderLayout(
 82+ 'columns',
 83+ array(
 84+ DataCenterViewHistory::typeHistory( $path, $asset )
 85+ )
 86+ );
 87+ }
 88+
7789 public function view(
7890 $path
7991 ) {
Index: trunk/extensions/DataCenter/Views/Facilities/Location.php
@@ -77,6 +77,18 @@
7878 );
7979 }
8080
 81+ public function history(
 82+ $path
 83+ ) {
 84+ $asset = DataCenterDB::getLocation( $path['id'] );
 85+ return DataCenterUI::renderLayout(
 86+ 'columns',
 87+ array(
 88+ DataCenterViewHistory::typeHistory( $path, $asset )
 89+ )
 90+ );
 91+ }
 92+
8193 public function view(
8294 $path
8395 ) {
Index: trunk/extensions/DataCenter/DataCenter.i18n.php
@@ -166,6 +166,7 @@
167167 'datacenter-ui-heading-models-type' => '$1 Assets',
168168 'datacenter-ui-heading-attaching-type' => 'Attaching $1',
169169 'datacenter-ui-heading-configuring-type' => 'Configuring $1',
 170+ 'datacenter-ui-heading-difference' => 'Difference',
170171 // Bodies
171172 '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?',
172173 'datacenter-ui-body-invalid-request' => 'You have requested a page with an invalid path.',

Status & tagging log