@@ -9,14 +9,202 @@ public function getIndex()
9
9
$ this ->setViewData ('projects ' , $ projects );
10
10
}
11
11
12
+ public function getCreate ()
13
+ {
14
+ // get user groups
15
+
16
+ $ this ->setViewData ('owners ' , array ('user: ' . Auth::user ()->id => 'User: ' . Auth::user ()->username ));
17
+ }
18
+
19
+ public function postCreate ()
20
+ {
21
+ $ input = e_array (Input::all ());
22
+
23
+ if ($ input != null ) {
24
+ $ owner = explode (': ' , $ input ['owner ' ]);
25
+
26
+ $ project = new Project ;
27
+ $ project ->name = $ input ['name ' ];
28
+ $ project ->privateFlag = isset ($ input ['privateFlag ' ]) ? $ input ['privateFlag ' ] : '0 ' ;
29
+ $ project ->ownerType = $ owner [0 ];
30
+ $ project ->ownerId = $ owner [1 ];
31
+ $ project ->creatorId = Auth::user ()->id ;
32
+
33
+ $ this ->checkErrorsSave ($ project );
34
+ }
35
+
36
+ return $ this ->redirect ('/project ' );
37
+ }
38
+
39
+ public function getCreateTable ($ projectId )
40
+ {
41
+ $ project = Project::find ($ projectId );
42
+ $ engine = array ('myisam ' => 'MyiSAM ' , 'innodb ' => 'InnoDB ' );
43
+ $ template = Template::all ();
44
+
45
+ Menu::setItemList ('main ' , new Menu \Items \ItemList );
46
+
47
+ Menu::handler ('main ' )
48
+ ->add ('/ ' , 'Home ' )
49
+ ->add ('javascript:void(0); ' , $ project ->name . ' Scheme ' , Menu::items ()
50
+ ->add ('/project/buildAll/ ' . $ project ->id , 'Full project build ' )
51
+ ->add ('/project/buildAllModels/ ' . $ project ->id , 'Build all modles ' )
52
+ ->add ('/project/buildAllMigration/ ' . $ project ->id , 'Build all migrations ' )
53
+ ->add ('/project/buildAllSeeds/ ' . $ project ->id , 'Build all seeds ' )
54
+ ->add ('/project/builds/ ' . $ project ->id , 'Project Builds ' )
55
+ )
56
+ ->add ('/project/create-table/ ' . $ project ->id , 'Add Table ' );
57
+
58
+ $ this ->setMenu ();
59
+
60
+ $ this ->setViewData ('template ' , $ template ->lists ('name ' , 'id ' ));
61
+ $ this ->setViewData ('engine ' , $ engine );
62
+ $ this ->setViewData ('project ' , $ project );
63
+ }
64
+
65
+ public function postCreateTable ()
66
+ {
67
+ $ input = e_array (Input::all ());
68
+
69
+ if ($ input != null ) {
70
+ $ project = new Table ;
71
+ $ project ->projectId = $ input ['projectId ' ];
72
+ $ project ->name = $ input ['name ' ];
73
+ $ project ->className = $ input ['className ' ];
74
+ $ project ->namespace = $ input ['namespace ' ];
75
+ $ project ->timestampsFlag = isset ($ input ['timestampsFlag ' ]) ? $ input ['timestampsFlag ' ] : 0 ;
76
+ $ project ->softDeletesFlag = isset ($ input ['softDeletesFlag ' ]) ? $ input ['softDeletesFlag ' ] : 0 ;
77
+ $ project ->tableTemplateId = $ input ['templateId ' ];
78
+ $ project ->postionLeft = 30 ;
79
+ $ project ->postionTop = 60 ;
80
+ $ project ->extends = $ input ['extends ' ];
81
+
82
+ $ this ->checkErrorsSave ($ project );
83
+ }
84
+
85
+ return $ this ->redirect ('/project/view/ ' . $ input ['projectId ' ]);
86
+ }
87
+
88
+ public function getCreateColumn ($ tableId )
89
+ {
90
+ $ columnTypes = Column_Type::all ();
91
+
92
+ $ columnAttributes = [
93
+ 'NONE ' => 'None ' ,
94
+ // 'BINARY' => '',
95
+ 'UNSIGNED ' => 'Unsigned ' ,
96
+ // 'UNSIGNED ZEROFILL' => ''
97
+ ];
98
+
99
+ $ indexes = [
100
+ 'NONE ' => 'None ' ,
101
+ 'INDEX ' => 'Index ' ,
102
+ 'PRIMARY_KEY ' => 'Primary Key ' ,
103
+ 'UNIQUE ' => 'Unique '
104
+ ];
105
+
106
+ $ this ->setViewData ('columnAttributes ' , $ columnAttributes );
107
+ $ this ->setViewData ('indexes ' , $ indexes );
108
+ $ this ->setViewData ('columnTypes ' , $ columnTypes ->lists ('name ' , 'id ' ));
109
+ $ this ->setViewData ('tableId ' , $ tableId );
110
+ }
111
+
112
+ public function postCreateColumn ()
113
+ {
114
+ $ input = e_array (Input::all ());
115
+
116
+ if ($ input != null ) {
117
+ $ table = Table::find ((int ) $ input ['tableId ' ]);
118
+
119
+ $ column = new Column ;
120
+ $ column ->tableId = $ table ->id ;
121
+ $ column ->name = $ input ['name ' ];
122
+ $ column ->typeId = $ input ['typeId ' ];
123
+ $ column ->defaultValue = $ input ['defaultValue ' ];
124
+ $ column ->value = $ input ['value ' ];
125
+ $ column ->attribute = $ input ['attribute ' ]; // Should this be an unsigned flag?
126
+ $ column ->index = $ input ['index ' ];
127
+ $ column ->nullableFlag = isset ($ input ['nullableFlag ' ]) ? $ input ['nullableFlag ' ] : 0 ;
128
+ $ column ->autoIncrementFlag = isset ($ input ['autoIncrementFlag ' ]) ? $ input ['autoIncrementFlag ' ] : 0 ;
129
+ $ column ->fillableFlag = isset ($ input ['fillableFlag ' ]) ? $ input ['fillableFlag ' ] : 0 ;
130
+ $ column ->visibleFlag = isset ($ input ['visibleFlag ' ]) ? $ input ['visibleFlag ' ] : 0 ;
131
+ $ column ->guardedFlag = isset ($ input ['guardedFlag ' ]) ? $ input ['guardedFlag ' ] : 0 ;
132
+ $ column ->hiddenFlag = isset ($ input ['hiddenFlag ' ]) ? $ input ['hiddenFlag ' ] : 0 ;
133
+ $ column ->order = count ($ table ->columns );
134
+
135
+ $ this ->checkErrorsSave ($ column );
136
+ }
137
+
138
+ return $ this ->redirect ('/project/view/ ' . $ table ->projectId );
139
+ }
140
+
12
141
public function getView ($ scheme )
13
142
{
14
- $ scheme = Project::find ($ scheme );
143
+ // eager load data needed to generate page.
144
+ $ scheme = Project::with ([
145
+ 'tables ' ,
146
+ 'tables.columns ' => function ($ query ) {
147
+ $ query ->orderBy ('order ' , 'asc ' );
148
+ },
149
+ 'tables.columns.type ' ,
150
+ 'tables.template ' ,
151
+ 'tables.local ' ,
152
+ 'tables.local.type ' ,
153
+ 'tables.foreign ' ,
154
+ 'tables.foreign.type ' ,
155
+ 'tables.through ' ,
156
+ 'tables.through.type '
157
+ ])
158
+ ->find ($ scheme );
159
+
160
+ Menu::setItemList ('main ' , new Menu \Items \ItemList );
161
+
15
162
Menu::handler ('main ' )
16
- ->add ('javascript:void(0); ' , $ scheme ->name , Menu::items ()
17
- ->add ('/scheme/buildAll ' , 'Full project build ' )
18
- ->add ('/scheme/buildAllModels ' , 'Build all modles ' )
19
- ->add ('/scheme/buildAllMigration ' , 'Build all migrations ' )
20
- ->add ('/scheme/buildAllSeeds ' , 'Build all seeds ' ));
163
+ ->add ('/ ' , 'Home ' )
164
+ ->add ('javascript:void(0); ' , $ scheme ->name . ' Scheme ' , Menu::items ()
165
+ ->add ('/project/buildAll/ ' . $ scheme ->id , 'Full project build ' )
166
+ ->add ('/project/buildAllModels/ ' . $ scheme ->id , 'Build all modles ' )
167
+ ->add ('/project/buildAllMigration/ ' . $ scheme ->id , 'Build all migrations ' )
168
+ ->add ('/project/buildAllSeeds/ ' . $ scheme ->id , 'Build all seeds ' )
169
+ ->add ('/project/builds/ ' . $ scheme ->id , 'Project Builds ' )
170
+ )
171
+ ->add ('/project/create-table/ ' . $ scheme ->id , 'Add Table ' );
172
+
173
+ $ this ->setMenu ();
174
+
175
+ $ this ->setViewData ('scheme ' , $ scheme );
176
+ }
177
+
178
+ public function postUpdateTableLocation ()
179
+ {
180
+ $ input = Input::all ();
181
+
182
+ $ input ['id ' ] = str_replace ('dbtable_ ' , '' , $ input ['id ' ]);
183
+
184
+ $ table = Table::find ((int ) $ input ['id ' ]);
185
+ $ table ->postionLeft = (int ) $ input ['postionLeft ' ];
186
+ $ table ->postionTop = (int ) $ input ['postionTop ' ];
187
+ $ table ->save ();
188
+
189
+ // return true;
190
+ }
191
+
192
+ public function postUpdateTableOrder ()
193
+ {
194
+ $ input = Input::all ();
195
+
196
+ $ columns = explode (', ' , $ input ['order ' ]);
197
+ foreach ($ columns as $ key => $ column ) {
198
+ $ column = Column::find ($ column );
199
+ $ column ->order = $ key ;
200
+ $ column ->save ();
201
+ }
202
+
203
+ // return true;
204
+ }
205
+
206
+ public function postUpdateColumnOrder ($ table , $ order )
207
+ {
208
+
21
209
}
22
210
}
0 commit comments