public function actions()
{
$actions = parent::actions();
unset($actions['create'], $actions['update'], $actions['delete']);
$actions['index'] = [
'class' => 'yii\rest\IndexAction',
'modelClass' => $this->modelClass,
'prepareDataProvider' => function () {
$model = new $this->modelClass;
$dataProvider = new SqlDataProvider([
'sql' => "SELECT *, ST_AsGeoJSON(geom) AS geo_json FROM projects",
'pagination' => false,
]);
return $dataProvider;
},
];
return $actions;
}
"SELECT *, ST_AsGeoJSON(geom) AS geo_json FROM projects"
public function behaviors() {
return array_merge(parent::behaviors(), [
'corsFilter' => [
'class' => \yii\filters\Cors::className(),
'cors' => [
'Origin' => ['http://localhost:3000'],
'Access-Control-Request-Method' => ['POST', 'GET'],
'Access-Control-Allow-Credentials' => true,
'Access-Control-Max-Age' => 3600,
],
],
]);
}
export default class MapService {
_apiBase = "http://otgr.frontend";
getResource = async (url) => {
const response = await fetch(`${this._apiBase}${url}`, {
mode: 'no-cors'
});
if (!response.ok) {
throw new Error(`Could not fetch ${url}, received ${response.status}`)
}
return response.json();
};
getProjects = async () => {
const response = await this.getResource('/project');
console.log(response);
//return await response.map(this._transformProject);
};
_transformProject = (project) => {
return {
id: project.id,
geom: project.geom,
name: project.name,
end_date: project.end_date,
contractor: project.contractor,
contract_number: project.contract_number,
volume: project.volume,
volume_type: project.volume_type,
data_path_request: project.data_path_request,
data_path_response: project.data_path_response,
passport_path: project.passport_path,
creation_date: project.creation_date,
creation_user_id: project.creation_user_id,
comments: project.comments,
locality: project.locality
}
};
}
export default class MapService {
_apiBase = "http://otgr.frontend";
getResource = async (url) => {
const response = await fetch(`${this._apiBase}${url}`);
if (!response.ok) {
throw new Error(`Could not fetch ${url}, received ${response.status}`)
}
return response.json();
};
getProjects = async () => {
const response = await this.getResource('/project');
console.log(response);
//return await response.map(this._transformProject);
};
_transformProject = (project) => {
return {
id: project.id,
geom: project.geom,
name: project.name,
end_date: project.end_date,
contractor: project.contractor,
contract_number: project.contract_number,
volume: project.volume,
volume_type: project.volume_type,
data_path_request: project.data_path_request,
data_path_response: project.data_path_response,
passport_path: project.passport_path,
creation_date: project.creation_date,
creation_user_id: project.creation_user_id,
comments: project.comments,
locality: project.locality
}
};
}
mediaUploader.on('select', function () {
attachment = mediaUploader.state().get('selection').first().toJSON();
insertImageAtCursor(attachment.url, attachment.title, attachment.alt);
});
function insertImageAtCursor(src, title, alt) {
var sel, range;
var image = document.createElement('img');
image.src = src;
image.title = title;
image.alt = alt;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode( image );
}
} else if (document.selection && document.selection.createRange) {
document.selection.createRange().innerHTML = image;
}
}