| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- <?php
- namespace zin;
- $apiHeader = $apiQuery = $apiParams = $apiResponse = array();
- $defaultTR = function()
- {
- return h::tr
- (
- setClass('input-row'),
- h::td
- (
- input
- (
- set::name('')
- )
- ),
- h::td
- (
- html("<input type='checkbox' />")
- ),
- h::td
- (
- textarea
- (
- set::rows(1)
- )
- ),
- h::td
- (
- div(setClass('pl-2 flex self-center line-btn'), btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ), btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- ))
- )
- );
- };
- if(!empty($api->params['header']))
- {
- foreach($api->params['header'] as $param)
- {
- $apiHeader[] = h::tr
- (
- setClass('input-row'),
- h::td
- (
- input
- (
- set::name(''),
- set::value($param['field'])
- )
- ),
- h::td
- (
- $param['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
- ),
- h::td
- (
- textarea
- (
- set::rows(1),
- set::value($param['desc'])
- )
- ),
- h::td
- (
- div
- (
- setClass('pl-2 flex self-center line-btn'),
- btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ),
- btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- )
- )
- )
- );
- }
- }
- else
- {
- $apiHeader[] = $defaultTR();
- }
- if(!empty($api->params['query']))
- {
- foreach($api->params['query'] as $query)
- {
- $apiQuery[] = h::tr
- (
- setClass('input-row'),
- h::td
- (
- input
- (
- set::name(''),
- set::value($query['field'])
- )
- ),
- h::td
- (
- $query['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
- ),
- h::td
- (
- textarea
- (
- set::rows(1),
- set::value($query['desc'])
- )
- ),
- h::td
- (
- div
- (
- setClass('pl-2 flex self-center line-btn'),
- btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ),
- btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- )
- )
- )
- );
- }
- }
- else
- {
- $apiQuery[] = $defaultTR();
- }
- $parseTree = function($data, $typeList, $level = 0) use (&$parseTree)
- {
- global $lang;
- $hidden = $data['paramsType'] == 'formData' ? 'hidden' : '';
- $tbody[] = h::tr
- (
- setClass('input-row'),
- setData(array('level' => $level + 1, 'key' => $data['key'], 'parent' => isset($data['parentKey']) ? $data['parentKey'] : 0)),
- h::td
- (
- $level ? setStyle('padding-left', ($level + 1) * 10 . 'px') : null,
- input
- (
- set::name(''),
- set::value($data['field'])
- )
- ),
- h::td
- (
- select
- (
- setClass('objectType'),
- set::name(''),
- set::value($data['paramsType']),
- set::items($typeList)
- )
- ),
- h::td
- (
- $data['required'] ? html("<input type='checkbox' checked/>") : html("<input type='checkbox'/>")
- ),
- h::td
- (
- textarea
- (
- set::rows(1),
- set::value($data['desc'])
- )
- ),
- h::td
- (
- div
- (
- setClass('pl-2 flex self-center line-btn'),
- btn
- (
- setClass("btn ghost btn-split $hidden"),
- icon('split')
- ),
- btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ),
- btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- )
- )
- )
- );
- if(isset($data['children']) && count($data['children']) > 0)
- {
- $level++;
- foreach($data['children'] as $item) $tbody[] = $parseTree($item, $typeList, $level);
- }
- return $tbody;
- };
- if(!empty($api->params['params']))
- {
- foreach($api->params['params'] as $param) $apiParams = array_merge($apiParams, $parseTree($param, $typeOptions));
- }
- else
- {
- $apiParams[] = h::tr
- (
- setClass('input-row'),
- setData(array('level' => 1, 'key' => 'origin', 'parent' => '0')),
- h::td
- (
- input
- (
- set::name('')
- )
- ),
- h::td
- (
- select
- (
- setClass('objectType'),
- set::name(''),
- set::value('object'),
- set::items($lang->api->paramsTypeOptions)
- )
- ),
- h::td
- (
- html("<input type='checkbox' />")
- ),
- h::td
- (
- textarea
- (
- set::rows(1)
- )
- ),
- h::td
- (
- div
- (
- setClass('pl-2 flex self-center line-btn'),
- btn
- (
- setClass('btn ghost btn-split hidden'),
- icon('split')
- ),
- btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ),
- btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- )
- )
- )
- );
- }
- if(!empty($api->response))
- {
- foreach($api->response as $param) $apiResponse = array_merge($apiResponse, $parseTree($param, $typeOptions));
- }
- else
- {
- $apiResponse[] = h::tr
- (
- setClass('input-row'),
- setData(array('level' => 1, 'key' => 'origin', 'parent' => '0')),
- h::td
- (
- input
- (
- set::name('')
- )
- ),
- h::td
- (
- select
- (
- setClass('objectType'),
- set::name(''),
- set::value('object'),
- set::items($lang->api->paramsTypeOptions)
- )
- ),
- h::td
- (
- html("<input type='checkbox' />")
- ),
- h::td
- (
- textarea
- (
- set::rows(1)
- )
- ),
- h::td
- (
- div
- (
- setClass('pl-2 flex self-center line-btn'),
- btn
- (
- setClass('btn ghost btn-split'),
- icon('split')
- ),
- btn
- (
- setClass('btn ghost btn-add'),
- icon('plus')
- ),
- btn
- (
- setClass('btn ghost btn-delete'),
- icon('trash')
- )
- )
- )
- );
- }
- formPanel
- (
- to::heading
- (
- div
- (
- setClass('panel-title text-lg'),
- $title
- )
- ),
- formGroup
- (
- set::width('1/2'),
- set::label($lang->api->module),
- picker
- (
- set::items($moduleOptionMenu),
- set::name('module'),
- set::value($api->module),
- set::required(true)
- )
- ),
- formGroup
- (
- set::width('1/2'),
- set::required(true),
- set::label($lang->api->title),
- input
- (
- set::name('title'),
- set::value($api->title)
- )
- ),
- formRow
- (
- formGroup
- (
- set::width('330px'),
- set::required(true),
- set::label($lang->api->path),
- inputGroup
- (
- picker
- (
- set::required(true),
- set::items($lang->api->protocalOptions),
- set::name('protocol'),
- set::value($api->protocol)
- ),
- picker
- (
- set::required(true),
- set::width('1/5'),
- set::items($lang->api->methodOptions),
- set::name('method'),
- set::value($api->method)
- )
- )
- ),
- formGroup
- (
- input
- (
- set::name('path'),
- set::value($api->path)
- )
- )
- ),
- formGroup
- (
- set::width('2/5'),
- set::label($lang->api->requestType),
- picker
- (
- set::name('requestType'),
- set::value($api->requestType),
- set::items($lang->api->requestTypeOptions)
- )
- ),
- formGroup
- (
- set::label($lang->api->status),
- radioList
- (
- set::name('status'),
- set::inline(true),
- set::value($api->status),
- set::items($lang->api->statusOptions)
- )
- ),
- formGroup
- (
- set::width('2/5'),
- set::label($lang->api->owner),
- picker
- (
- set::name('owner'),
- set::items($allUsers),
- set::value($api->owner)
- )
- ),
- formGroup
- (
- setID('form-header'),
- setClass('params-group'),
- set::label($lang->api->header),
- h::table
- (
- setClass('table condensed bordered'),
- h::tr
- (
- h::th
- (
- width('300px'),
- $lang->struct->field
- ),
- h::th
- (
- width('70px'),
- $lang->struct->required
- ),
- h::th
- (
- $lang->struct->desc
- ),
- h::th
- (
- width('100px')
- )
- ),
- $apiHeader
- )
- ),
- formGroup
- (
- setID('form-query'),
- setClass('params-group'),
- set::label($lang->api->query),
- h::table
- (
- setClass('table condensed bordered'),
- h::tr
- (
- h::th
- (
- width('300px'),
- $lang->struct->field
- ),
- h::th
- (
- width('70px'),
- $lang->struct->required
- ),
- h::th
- (
- $lang->struct->desc
- ),
- h::th
- (
- width('100px')
- )
- ),
- $apiQuery
- )
- ),
- formGroup
- (
- setID('form-paramsType'),
- setClass('params-group'),
- set::label($lang->struct->type),
- radioList
- (
- set::name('type'),
- set::inline(true),
- set::value(!empty($api->params['paramsType']) ? $api->params['paramsType'] : ''),
- set::items($lang->struct->typeOptions)
- )
- ),
- formGroup
- (
- setID('form-params'),
- setClass('params-group'),
- set::label($lang->api->params),
- h::table
- (
- setClass('table condensed bordered'),
- h::tr
- (
- h::th
- (
- width('300px'),
- $lang->struct->field
- ),
- h::th
- (
- width('100px'),
- $lang->struct->paramsType
- ),
- h::th
- (
- width('70px'),
- $lang->struct->required
- ),
- h::th
- (
- $lang->struct->desc
- ),
- h::th
- (
- width('100px')
- )
- ),
- $apiParams
- )
- ),
- formHidden('params', json_encode($api->params)),
- formGroup
- (
- set::width('1/2'),
- set::label($lang->api->paramsExample),
- textarea
- (
- set::name('paramsExample'),
- set::value($api->paramsExample)
- )
- ),
- formGroup
- (
- setID('form-response'),
- setClass('response'),
- set::label($lang->api->response),
- h::table
- (
- setClass('table condensed bordered'),
- h::tr
- (
- h::th
- (
- width('300px'),
- $lang->struct->field
- ),
- h::th
- (
- width('100px'),
- $lang->struct->paramsType
- ),
- h::th
- (
- width('70px'),
- $lang->struct->required
- ),
- h::th
- (
- $lang->struct->desc
- ),
- h::th
- (
- width('100px')
- )
- ),
- $apiResponse
- )
- ),
- formHidden('response', json_encode($api->response)),
- formGroup
- (
- set::width('1/2'),
- set::label($lang->api->responseExample),
- textarea
- (
- set::name('responseExample'),
- set::value($api->responseExample)
- )
- ),
- formGroup
- (
- set::label($lang->api->desc),
- editor
- (
- set::name('desc'),
- html($api->desc)
- )
- ),
- formHidden('editedDate', $api->editedDate)
- );
|