@@ -21,6 +21,7 @@ import AttachSelectedRowsDialog from 'dashboard/Data/Browser/AttachSel
2121import CloneSelectedRowsDialog from 'dashboard/Data/Browser/CloneSelectedRowsDialog.react' ;
2222import EditRowDialog from 'dashboard/Data/Browser/EditRowDialog.react' ;
2323import ExportSelectedRowsDialog from 'dashboard/Data/Browser/ExportSelectedRowsDialog.react' ;
24+ import ExportSchemaDialog from 'dashboard/Data/Browser/ExportSchemaDialog.react' ;
2425import { List , Map } from 'immutable' ;
2526import Notification from 'dashboard/Data/Browser/Notification.react' ;
2627import Parse from 'parse' ;
@@ -56,6 +57,7 @@ class Browser extends DashboardView {
5657 showRemoveColumnDialog : false ,
5758 showDropClassDialog : false ,
5859 showExportDialog : false ,
60+ showExportSchemaDialog : false ,
5961 showAttachRowsDialog : false ,
6062 showEditRowDialog : false ,
6163 showPointerKeyDialog : false ,
@@ -88,7 +90,7 @@ class Browser extends DashboardView {
8890 requiredColumnFields : [ ] ,
8991
9092 useMasterKey : true ,
91- currentUser : Parse . User . current ( )
93+ currentUser : Parse . User . current ( ) ,
9294 } ;
9395
9496 this . prefetchData = this . prefetchData . bind ( this ) ;
@@ -114,6 +116,7 @@ class Browser extends DashboardView {
114116 this . confirmCloneSelectedRows = this . confirmCloneSelectedRows . bind ( this ) ;
115117 this . cancelCloneSelectedRows = this . cancelCloneSelectedRows . bind ( this ) ;
116118 this . showExportSelectedRowsDialog = this . showExportSelectedRowsDialog . bind ( this ) ;
119+ this . showExportSchemaDialog = this . showExportSchemaDialog . bind ( this ) ;
117120 this . confirmExportSelectedRows = this . confirmExportSelectedRows . bind ( this ) ;
118121 this . cancelExportSelectedRows = this . cancelExportSelectedRows . bind ( this ) ;
119122 this . getClassRelationColumns = this . getClassRelationColumns . bind ( this ) ;
@@ -326,6 +329,37 @@ class Browser extends DashboardView {
326329 } ) ;
327330 }
328331
332+ async exportSchema ( className , all ) {
333+ try {
334+ this . showNote ( 'Exporting schema...' ) ;
335+ this . setState ( { showExportSchemaDialog : false } ) ;
336+ let schema = [ ] ;
337+ if ( all ) {
338+ schema = await Parse . Schema . all ( ) ;
339+ } else {
340+ schema = await new Parse . Schema ( className ) . get ( ) ;
341+ }
342+ const element = document . createElement ( 'a' ) ;
343+ const file = new Blob (
344+ [
345+ JSON . stringify (
346+ schema ,
347+ null ,
348+ 2 ,
349+ ) ,
350+ ] ,
351+ { type : 'application/json' }
352+ ) ;
353+ element . href = URL . createObjectURL ( file ) ;
354+ element . download = `${ all ? 'schema' : className } .json` ;
355+ document . body . appendChild ( element ) ; // Required for this to work in FireFox
356+ element . click ( ) ;
357+ document . body . removeChild ( element ) ;
358+ } catch ( msg ) {
359+ this . showNote ( msg , true ) ;
360+ }
361+ }
362+
329363 newColumn ( payload , required ) {
330364 return this . props . schema . dispatch ( ActionTypes . ADD_COLUMN , payload )
331365 . then ( ( ) => {
@@ -1089,6 +1123,7 @@ class Browser extends DashboardView {
10891123 this . state . showRemoveColumnDialog ||
10901124 this . state . showDropClassDialog ||
10911125 this . state . showExportDialog ||
1126+ this . state . showExportSchema ||
10921127 this . state . rowsToDelete ||
10931128 this . state . showAttachRowsDialog ||
10941129 this . state . showAttachSelectedRowsDialog ||
@@ -1249,6 +1284,12 @@ class Browser extends DashboardView {
12491284 } ) ;
12501285 }
12511286
1287+ showExportSchemaDialog ( ) {
1288+ this . setState ( {
1289+ showExportSchemaDialog : true
1290+ } )
1291+ }
1292+
12521293 cancelExportSelectedRows ( ) {
12531294 this . setState ( {
12541295 rowsToExport : null
@@ -1545,6 +1586,7 @@ class Browser extends DashboardView {
15451586 onEditSelectedRow = { this . showEditRowDialog }
15461587 onEditPermissions = { this . onDialogToggle }
15471588 onExportSelectedRows = { this . showExportSelectedRowsDialog }
1589+ onExportSchema = { this . showExportSchemaDialog }
15481590
15491591 onSaveNewRow = { this . saveNewRow }
15501592 onShowPointerKey = { this . showPointerKeyDialog }
@@ -1659,6 +1701,14 @@ class Browser extends DashboardView {
16591701 onCancel = { ( ) => this . setState ( { showExportDialog : false } ) }
16601702 onConfirm = { ( ) => this . exportClass ( className ) } />
16611703 ) ;
1704+ } else if ( this . state . showExportSchemaDialog ) {
1705+ extras = (
1706+ < ExportSchemaDialog
1707+ className = { className }
1708+ schema = { this . props . schema . data . get ( 'classes' ) }
1709+ onCancel = { ( ) => this . setState ( { showExportSchemaDialog : false } ) }
1710+ onConfirm = { ( ...args ) => this . exportSchema ( ...args ) } />
1711+ ) ;
16621712 } else if ( this . state . showAttachRowsDialog ) {
16631713 extras = (
16641714 < AttachRowsDialog
0 commit comments