063 default_compute svc.sort
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<cfcomponent extends="taffy.core.resource" taffy:uri="/instanceOperations/default/{svcOperationId}" hint="template for default instance operation">
|
||||
|
||||
<cfsilent>
|
||||
<cfimport prefix="m" taglib="../lib"/>
|
||||
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/>
|
||||
</cfsilent>
|
||||
|
||||
|
||||
<cffunction name="get" hint="Шаблон операции экземпляра"><!--- *** TODO проверка принадлежности тенанту --->
|
||||
<cfargument name="svcOperationId" type="string" required=true hint="type:integer"/>
|
||||
<cfargument name="usrId" type="string" required=true hint="type:integer"/><!--- arguments.usrId неявно инжектируется из Application.cfm --->
|
||||
|
||||
<cftry>
|
||||
<cfset this.helper.validateField(arguments, "svcOperationId", "integer")/>
|
||||
<cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfquery name="local.qSvcOperation" result="local.result">
|
||||
select
|
||||
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
|
||||
<m:field title="ID" cfSqlType="CF_SQL_INTEGER">o.svc_operation_id</m:field>
|
||||
<m:field>o.svc_id</m:field>
|
||||
<m:field title="operation">o.operation</m:field>
|
||||
<m:field title="URL">o.url</m:field>
|
||||
<m:field title="Описание">o.descr</m:field>
|
||||
<m:field title="Руководство">o.man</m:field>
|
||||
</m:field_set>
|
||||
from svc_operation o
|
||||
where o.svc_operation_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcOperationId#" null=#!isValid('integer',arguments.svcOperationId)#/>
|
||||
</cfquery>
|
||||
|
||||
<cfquery name="local.qCfsParam" result="local.result">
|
||||
select
|
||||
<m:field_set titleMapOut="local.cfsParamMap" lengthOut="local.fieldCount">
|
||||
<m:field title="ID" cfSqlType="CF_SQL_INTEGER">p.svc_operation_cfs_param_id</m:field>
|
||||
<!--- <m:field cfSqlType="CF_SQL_INTEGER">p.svc_operation_id</m:field> --->
|
||||
<m:field>p.svc_operation_cfs_param</m:field>
|
||||
<m:field>p.label</m:field>
|
||||
<m:field>p.data_type</m:field>
|
||||
<m:field formatter=#function(x){return listToArray(x);}#>p.value_list</m:field>
|
||||
<m:field>p.ref_svc_id</m:field>
|
||||
<m:field formatter=#request.castToBool#>p.is_required</m:field>
|
||||
<m:field>p.default_value</m:field><!--- can be overridden bu default_compute --->
|
||||
<m:field>p.default_compute</m:field>
|
||||
<m:field>p.regex</m:field>
|
||||
<m:field>p.unique_scope</m:field>
|
||||
<m:field>p.maxlength</m:field>
|
||||
<m:field>p.minlength</m:field>
|
||||
<m:field>p.maxvalue</m:field>
|
||||
<m:field>p.minvalue</m:field>
|
||||
<m:field>p.descr</m:field>
|
||||
<m:field>p.man</m:field>
|
||||
<m:field>p.sort</m:field>
|
||||
<m:field formatter=#request.castToBool#>(
|
||||
select 1 from svc_operation_cfs_param m
|
||||
join svc_operation om on (m.svc_operation_id=om.svc_operation_id)
|
||||
join svc_operation oc on (om.svc_id=oc.svc_id AND om.operation='modify' AND oc.operation='create')
|
||||
join svc_operation_cfs_param c on (oc.svc_operation_id=c.svc_operation_id AND m.svc_operation_cfs_param=c.svc_operation_cfs_param)
|
||||
where c.svc_operation_cfs_param_id=p.svc_operation_cfs_param_id
|
||||
order by c.svc_operation_cfs_param_id
|
||||
limit 1
|
||||
) as isModifiable</m:field>
|
||||
</m:field_set>
|
||||
from svc_operation_cfs_param p
|
||||
where p.svc_operation_id=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.svcOperationId#" null=#!isValid('integer',arguments.svcOperationId)#/>
|
||||
order by p.sort, p.svc_operation_cfs_param_id
|
||||
</cfquery>
|
||||
|
||||
<cfif local.qSvcOperation.recordCount EQ 0>
|
||||
<cfreturn representationOf(this.helper.formatMessage("Not Found")).withStatus(404)/>
|
||||
</cfif>
|
||||
|
||||
<cfset var out=structNew("linked")/>
|
||||
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
||||
|
||||
<cfset "out.svcOperation" = this.helper.appendRecord(
|
||||
structNew("linked"), "", local.titleMap, local.qSvcOperation, this.helper.snake2camel
|
||||
)/>
|
||||
|
||||
<cfset "out.svcOperation.cfsParams"=[]/>
|
||||
<cfloop query=#local.qCfsParam#>
|
||||
<cfset local.qCfsParam.default_value = computeDefault(local.qCfsParam.default_compute, local.qCfsParam.default_value, qSvcOperation.svc_id, arguments.usrId)/><!--- *** не очень хорошо модифицировать запрос --->
|
||||
<cfset var rec = this.helper.appendRecord(structNew("linked"), "", local.cfsParamMap, local.qCfsParam, this.helper.snake2camel)/>
|
||||
<cfset arrayAppend(out.svcOperation.cfsParams, rec)/>
|
||||
</cfloop>
|
||||
|
||||
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
|
||||
<cfreturn representationOf(out) />
|
||||
</cffunction>
|
||||
|
||||
<!--- *** выглядит ужасно, но красивый вариант не придумывается ряд месяцев --->
|
||||
<cffunction name="computeDefault">
|
||||
<cfargument name="defaultCompute"/>
|
||||
<cfargument name="original"/>
|
||||
<cfargument name="service_id" type="numeric"/>
|
||||
<cfargument name="usr_id" type="numeric"/>
|
||||
|
||||
<cfswitch expression=#arguments.defaultCompute#>
|
||||
<cfcase value="display_name">
|
||||
<cfreturn CreateObject("component", "instance_ls").generateDefaultName(arguments.service_id,arguments.usr_id)/>
|
||||
</cfcase>
|
||||
<cfdefaultcase>
|
||||
<cfreturn #arguments.original#/>
|
||||
</cfdefaultcase>
|
||||
</cfswitch>
|
||||
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
@@ -11,6 +11,7 @@
|
||||
dt_updated={prefix="s", type="date"},
|
||||
svc_id={prefix="s", type="integer"},
|
||||
resource_realm_type_id={prefix="s", type="integer"},
|
||||
sort={prefix="s", type="integer"},
|
||||
is_production_ready={prefix="s", type="boolean"},
|
||||
svc={prefix="s", type="string"},
|
||||
svc_short={prefix="s", type="string"},
|
||||
@@ -66,6 +67,7 @@
|
||||
<m:field title="URL создания">(select url from svc_operation so where so.operation='create' AND so.svc_id=s.svc_id limit 1) as create_url</m:field>
|
||||
<m:field formatter=#function(x){return x NEQ 0}#>s.is_production_ready</m:field>
|
||||
<m:field>s.resource_realm_type_id</m:field>
|
||||
<m:field>s.sort</m:field>
|
||||
<m:field>s.version</m:field>
|
||||
<m:field>s.descr</m:field>
|
||||
<m:field>s.man</m:field>
|
||||
|
||||
Reference in New Issue
Block a user