middleware('auth'); $this->_service = 'catalog'; $this->_module = 'activity'; $this->_viewname = 'activity'; $this->_title = 'Activity Import'; $this->_base_url = '/activityimport'; } protected function get_list_fields(){ return [ 'actions' => ['title' => 'Actions', 'buttons' => [ 'edit', 'delete' ] ], 'title' => ['title' => 'Title', 'type' => 'text'], 'status' => ['title' => 'Status', 'type' => 'text'], 'createdAt' => ['title' => 'Created At', 'type' => 'text'], ]; } public function list(Request $request) { $response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/import_list'); //echo '
'; print_r($response); exit;
if($response->statusCode == 401) {
return redirect('/unauthorised');
}
$fields = $this->get_list_fields();
//echo ''; print_r($fields); exit;
return $this->view($this->_listtype)->with([
'title' => $this->_title,
'fields' => $fields,
'base_url' => $this->_base_url,
'items' => $response->data->items,
'buttons' => $this->get_list_buttons()
]);
}
protected function get_form_fields($type, $values){
$mappings = $this->getlambda('get', 'metric', 'injestion_mapping', 'get_all');
$mappings_dd = [];
foreach($mappings->data->items as $mapping){
$mappings_dd[$mapping->id] = $mapping->name;
}
//echo ''; print_r($mappings_dd); exit;
return [
'title' => ['title' => 'Title', 'type' => 'text', 'required' => true],
'status' => ['title' => 'Status', 'type' => 'select', 'required' => true, 'values' => ['active' => 'Active', 'disabled' => 'Disabled'] ],
'file' => ['title' => 'File Upload', 'type' => 'file', 'required' => true],
'mapping_id' => ['title' => 'Select Mapping', 'type' => 'select', 'values' => $mappings_dd ],
];
}
public function form($type, $id = null) {
$values = [];
if($type == 'edit') {
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/import_detail', ['id' => $id]);
$values = $response->data->item;
//echo ''; print_r($values); exit;
}
//echo ''; print_r($values); exit;
$data = $this->_beforeform($type, $values);
$fields = $this->get_form_fields($type, $values);
//echo ''; print_r($fields); exit;
return $this->view('form')->with([
'title' => $this->_title,
'mode' => $type,
'fields' => $fields,
'base_url' => $this->_base_url,
'item' => $values,
]);
}
protected function _beforesave($type, $request) {
$data = $request->except('_token');
if( $request->file('file') ) {
$data['file'] = $this->_uploadMedia($request, 'file', 'activity_import');
}
return $data;
}
protected function _beforeform($type, $values) {
// if($type == 'edit') {
// $values->channels = explode('#', $values->channels);
// }
//echo ''; print_r($values); exit;
return $values;
}
public function processimport(Request $request) {
$id = $request->input('id', 0);
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/step', ['id'=>$id, 'step'=>'status']);
//echo ''; print_r($response); exit;
return $this->view('processimport')->with(['id'=>$id, 'title'=>$response->data->status->title, 'status'=>$response->data->status->status, 'context'=>$response->data->status->context ]);
}
public function step(Request $request) {
$id = $request->input('id', 0);
$step = $request->input('step', 0);
try {
LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/step', ['id'=>$id, 'step'=>$step]);
} catch (ConnectionException $e) {
return redirect('/activityimport/stepresponse?id='.$id.'&step='.$step);
}
}
public function stepresponse(Request $request) {
$id = $request->input('id', 0);
$step = $request->input('step', 0);
return $this->view('stepresponse')->with(['id'=>$id, 'step'=>$step]);
}
public function checkstatus(Request $request) {
$id = $request->input('id', 0);
$step = $request->input('step', 0);
$response = LambdaRequest::signedrequest('get', $this->_service, $this->_module.'/step', ['id'=>$id, 'step'=>'status']);
return response()->json($response->data->status);
}
}