middleware('auth'); $this->_service = 'metric'; $this->_module = 'injestion_mapping'; $this->_viewname = 'metricmap'; $this->_title = 'Metric Injestion Mapping'; $this->_base_url = '/metricmapping'; } protected function get_list_fields(){ return [ 'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ], 'id' => ['title' => 'Auth Key', 'type' => 'text'], 'name' => ['title' => 'Mapping Name', 'type' => 'text'], 'status' => ['title' => 'Status', 'type' => 'select'], ]; } protected function get_form_fields($type, $values){ $metrics = $this->getlambda('get', 'metric', 'metric', 'get_all'); $metrics_dd = []; //echo '
'; print_r($metrics); exit;
        foreach($metrics->data->items as $metric){
            $metrics_dd[$metric->id] = $metric->name;
        }
        return [
            'name' => ['title' => 'Mapping Name', 'type' => 'text', 'required' => true],
            'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
            'mappings' => ['title' => 'Metric', 'type' => 'mapping', 'required' => true, 'metrics' => $metrics_dd, 'types' => ['unit' => 'Units', 'count' => 'Count'] , 'fullwidth' => true ],
        ];
    }

    protected function _beforesave($type, $request) {
        $data = $request->except('_token');
        $data['mappings'] = [];
        foreach($data['metric'] as $k => $metric) {
            $data['mappings'][] = ['metric' => $metric, 'type' => $data['type'][$k], 'attribute' => $data['attribute'][$k] ];
        }
        unset($data['metric']);
        unset($data['type']);
        unset($data['attribute']);
        return $data;
    }
}