-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathOpenStackReleaseAdminUI.php
More file actions
153 lines (131 loc) · 6.36 KB
/
Copy pathOpenStackReleaseAdminUI.php
File metadata and controls
153 lines (131 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Copyright 2014 Openstack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
/**
* Class OpenStackReleaseAdminUI
*/
final class OpenStackReleaseAdminUI extends DataExtension
{
private static $searchable_fields = array('Name', 'ReleaseDate');
/**
* @param FieldList $fields
* @return FieldList|void
*/
public function updateCMSFields(FieldList $fields)
{
$oldFields = $fields->toArray();
foreach ($oldFields as $field) {
$fields->remove($field);
}
$fields->push(new LiteralField("Title", "<h2>OpenStack Release</h2>"));
$fields->push(new TextField("Name", "Name"));
$date = DateField::create('ReleaseDate')->setConfig('showcalendar', true);
$fields->push($date);
$date->setTitle('Release Date');
$fields->push(new TextField("ReleaseNumber", "Release Number"));
$fields->push(new TextField("ReleaseNotesUrl", "Release Notes Url"));
$fields->push(new DropdownField(
'Status',
'Status',
$this->owner->dbObject('Status')->enumValues()
));
//components
if ($this->owner->ID > 0)
{
$openStackComponentFields = singleton('OpenStackComponent')->getCMSFields();
$openStackComponentFields->addField(
// The "ManyMany[<extradata-name>]" convention
new TextField('ManyMany[CustomTeamYAMLFileName]', 'Custom Team YAML File name ( full url path)')
);
$components_config = GridFieldConfig_RelationEditor::create(PHP_INT_MAX);
$components_config->getComponentByType('GridFieldDetailForm')->setFields($openStackComponentFields);
$components_config->addComponent(new GridFieldAjaxRefresh(1000, false));
$components = new GridField
(
"OpenStackComponents",
"Supported Release Components",
$this->owner->OpenStackComponents(),
$components_config
);
$components_config->removeComponentsByType('GridFieldAddNewButton');
$fields->push($components);
//supported versions
//only if we have components set
if ($this->owner->OpenStackComponents()->filter('SupportsVersioning', true)->count() > 0)
{
$supported_versions_config = new GridFieldConfig_RecordEditor(PHP_INT_MAX);
$dataColumns = $supported_versions_config->getComponentByType('GridFieldDataColumns');
$dataColumns->setDisplayFields(
[
'OpenStackComponent.CodeName' => 'Component CodeName',
'OpenStackComponent.Name' => 'Component Name',
'ApiVersion.Version' => 'Api Version',
'Status' => 'Status',
'CreatedFromTask' => 'CreatedFromTask',
]
);
$supported_versions_config->addComponent(new GridFieldAjaxRefresh(1000, false));
$supported_versions = new GridField("SupportedApiVersions", "Supported Release Components",
$this->owner->SupportedApiVersions(" ReleaseID = {$this->owner->getIdentifier()} AND OpenStackComponent.SupportsVersioning = 1 ")->innerJoin('OpenStackComponent',
'OpenStackComponent.ID = OpenStackReleaseSupportedApiVersion.OpenStackComponentID'),
$supported_versions_config);
$fields->push($supported_versions);
}
$config = new GridFieldConfig_RecordEditor(100);
$config_types = new GridField("SampleConfigurationTypes", "Sample Configuration Types",
$this->owner->SampleConfigurationTypes(),
$config);
$config->addComponent(new GridFieldSortableRows('Order'));
$fields->push($config_types);
}
return $fields;
}
public function onAfterWrite()
{
parent::onAfterWrite();
//create supported versions for not versioned components
$supported_components = $this->owner->OpenStackComponents();
if ($supported_components && count($supported_components) > 0) {
$non_versioned_components = array();
foreach ($supported_components as $component) {
if (!$component->getSupportsVersioning()) {
//crete dumb version
$non_versioned_components[] = $component->getIdentifier();
$old = $this->owner->SupportedApiVersions(" OpenStackComponentID = {$component->getIdentifier()} AND ApiVersionID = 0 ");
if (count($old) == 0) {
$new_supported_version = new OpenStackReleaseSupportedApiVersion;
$new_supported_version->OpenStackComponentID = $component->getIdentifier();
$new_supported_version->ReleaseID = $this->owner->getIdentifier();
$new_supported_version->ApiVersionID = 0;
$new_supported_version->write();
}
}
}
$to_delete = "";
if (count($non_versioned_components) > 0) {
$to_delete = implode(',', $non_versioned_components);
$to_delete = "AND OpenStackComponentID NOT IN ({$to_delete})";
}
DB::query("DELETE FROM OpenStackReleaseSupportedApiVersion WHERE ReleaseID = {$this->owner->getIdentifier()} AND ApiVersionID = 0 {$to_delete}");
}
}
function getCMSValidator()
{
return $this->getValidator();
}
function getValidator()
{
$validator = new RequiredFields(['Name', 'ReleaseNumber', 'ReleaseDate']);
return $validator;
}
}