Skip to content

Commit

Permalink
Add page to view edit history for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0001 committed Oct 19, 2024
1 parent 93dc18d commit 1339c5a
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 1 deletion.
31 changes: 31 additions & 0 deletions application/controllers/api/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct()
$this->load->model("Collection_model");

$this->load->library("Editor_acl");
$this->load->model("Audit_log_model");
$this->load->library("Audit_log");
$this->load->library("Project_search");
$this->load->library('Project_json_writer');
Expand Down Expand Up @@ -1286,4 +1287,34 @@ function collections_get($sid=null)
}
}


/**
*
* Get edit history for a project
*
*/
function history_get($sid=null)
{
try{
$sid=$this->get_sid($sid);
$this->editor_acl->user_has_project_access($sid,$permission='view',$this->api_user);

$result=$this->Audit_log_model->get_history($obj_type='project',$obj_id=$sid,$limit=10, $offset=0);
//array_walk($result, 'unix_date_to_gmt_row',array('created','changed'));

$response=array(
'status'=>'success',
'history'=>$result
);
$this->set_response($response, REST_Controller::HTTP_OK);
}
catch(Exception $e){
$error_output=array(
'status'=>'failed',
'message'=>$e->getMessage()
);
$this->set_response($error_output, REST_Controller::HTTP_BAD_REQUEST);
}
}

}
30 changes: 30 additions & 0 deletions application/models/Audit_log_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,34 @@ function get_recent_entries($limit=10)
return $query->result_array();
}


/**
*
* Returns the history of a specific object
*
*/
function get_history($obj_type,$obj_id,$limit=10, $offset=0)
{
$this->db->select('audit_logs.*, users.username, users.email');
$this->db->where('obj_type',$obj_type);
$this->db->where('obj_id',$obj_id);
$this->db->join('users', 'users.id = audit_logs.user_id');
$this->db->order_by('created','desc');
$this->db->limit($limit);

if ($offset>0){
$this->db->offset($offset);
}

$query = $this->db->get("audit_logs");
$result=$query->result_array();

foreach($result as $idx=>$row)
{
$result[$idx]['metadata']=json_decode($row['metadata'],true);
}

return $result;
}

}
6 changes: 6 additions & 0 deletions application/views/metadata_editor/index_vuetify.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function get_template_keys($items,&$output)
<script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js"></script>


<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/vue-json-pretty.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/styles.min.css">



<?php echo $this->load->view("metadata_editor/index_vuetify_main_app",null,true);?>

Expand Down Expand Up @@ -969,6 +973,8 @@ function(error) {
}
}
})

Vue.component('VueJsonPretty', VueJsonPretty.default);
</script>

<script>
Expand Down
5 changes: 4 additions & 1 deletion application/views/metadata_editor/index_vuetify_main_app.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
echo $this->load->view("project/vue-collection-share-component.js", null, true);
echo $this->load->view("metadata_editor/vue-summary-collections-component.js", null, true);
echo $this->load->view("metadata_editor/vue-textarea-latex-component.js", null, true);
echo $this->load->view("metadata_editor/vue-project-history-component.js",null,true);
?>

<?php if (empty($metadata)):?>
Expand Down Expand Up @@ -257,6 +258,7 @@
const GeoFeature ={props: ['feature_name'],template: '<div><geospatial-feature/></div>'}
const PagePreview ={template: '<div><page-preview/></div>'}
const GeoGallery ={template: '<div><geospatial-gallery/></div>'}
const ProjectHistory ={template: '<div><project-history/></div>'}

//routes
const routes = [
Expand All @@ -280,7 +282,8 @@
//{ path: '/files', component: FileManager, props: true},
{ path: '/geospatial-features', component: GeoFeatures, props: true},
{ path: '/geospatial-feature/:feature_name', component: GeoFeature, props: true },
{ path: '/geospatial-gallery', component: GeoGallery, props: true }
{ path: '/geospatial-gallery', component: GeoGallery, props: true },
{ path: '/history', component: ProjectHistory },
]

const router = new VueRouter({
Expand Down
95 changes: 95 additions & 0 deletions application/views/metadata_editor/vue-project-history-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Vue.component('project-history', {
props: [],
data() {
return {
is_loading: false,
history: [],
deep: 0
}
},
mounted:function(){
this.loadEditHistory();
},
methods: {
loadEditHistory: async function()
{
vm=this;
vm.is_loading=true;
let url=CI.base_url + '/api/editor/history/'+this.ProjectID;

let resp = await axios.get(url);

console.log(resp.data);

vm.history = resp.data;
vm.is_loading=false;
},
momentDate(date) {
return moment(date).format("YYYY/MM/DD hh:mm A");
},

},
computed: {
ProjectID(){
return this.$store.state.project_id;
},
ProjectTemplate(){
return this.$store.state.formTemplate;
},
TemplateItems()
{
return this.ProjectTemplate.template.items;
}

},
template: `
<div class="vue-project-history-component m-3 mt-5 ">
<div v-if="is_loading" class="text-center">
<v-progress-circular
indeterminate
color="primary"
></v-progress-circular>
</div>
<div v-else>
<div class="bg-light p-3">
Revisions
</div>
</div>
<v-simple-table v-if="history && history.history && history.history.length>0">
<template v-slot:default>
<thead>
<tr>
<th class="text-left" style="width:200px">Date</th>
<th class="text-left" style="width:100px">User</th>
<th class="text-left"></th>
</tr>
</thead>
<tbody>
<tr v-for="revision in history.history">
<td>{{momentDate(revision.created)}}</td>
<td>{{revision.username}}</td>
<td>
<div style="max-height:500px;overflow:auto">
<vue-json-pretty :data="revision.metadata" :deep="deep" />
</div>
</td>
</tr>
</tbody>
</template>
</v-simple-table>
<div v-else>
<v-alert outlined color="red">
No revisions found.
</v-alert>
</div>
</div>
`
});

0 comments on commit 1339c5a

Please sign in to comment.