Skip to content

Commit

Permalink
git update changes + better space overview with actions + new profile…
Browse files Browse the repository at this point in the history
… for osd for real data
  • Loading branch information
cedricdcc committed Apr 21, 2022
1 parent 50535e1 commit 3a75254
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 47 deletions.
17 changes: 14 additions & 3 deletions backend/app/model/rocrategit.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ def clone_content(location, repo_url):
try:
git.Repo.clone_from(ssh_url, location)
except:
log.info(f"deleting existing repo on location {location} for repo :{ssh_url}")
shutil.rmtree(location, onerror=on_rm_error)
git.Repo.clone_from(ssh_url, location)
try:
log.info(f"deleting existing repo on location {location} for repo :{ssh_url}")
shutil.rmtree(location, onerror=on_rm_error)
git.Repo.clone_from(ssh_url, location)
except:
# we make a new map for the repo to be cloned in (location)
# and then we delete the old one
try:
os.mkdir(location)
git.Repo.clone_from(ssh_url, location)
except Exception as e:
log.error(f"error cloning repo {ssh_url} to {location}")
log.exception(e)


@staticmethod
def update_content(location):
Expand Down
4 changes: 4 additions & 0 deletions backend/app/model/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ def __init__(self,storage_path,ro_profile,uuid=None,remote_url=None,workspace_pa
seed_dependencies = self.ro_profile.seed_dependencies
log.debug(seed_dependencies)
#TODO: get all the seed_dependencies from the given profile uuid

#TODO: Add a check on the created repo to see if the repo is not empty => if empty then copy over all the files from the seed repos else don't do anything

self.clone_repo(self.remote_url)
repos_to_copy_over = []
for seed_repo in seed_dependencies.keys():
repos_to_copy_over.append(seed_repo)
#copy over all the files from the repos
for repo in repos_to_copy_over:
self._copy_files_to_workspace(repo_url=repo)
self.clone_repo(self.remote_url)
#TODO: add the new metadata to the spaces.json file
self.write()
else:
Expand Down
35 changes: 32 additions & 3 deletions backend/app/routers/APIV1/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
from pathlib import Path as pads
from collections import MutableMapping
from fastapi.staticfiles import StaticFiles
import re
from fastapi.openapi.docs import (
get_redoc_html,
get_swagger_ui_html,
get_swagger_ui_oauth2_redirect_html,
)
import logging
log=logging.getLogger(__name__)

router = APIRouter(
prefix="/git",
Expand Down Expand Up @@ -115,12 +118,36 @@ def get_git_status(*,space_id: str = Path(None,description="space_id name")):
space_folder = data[space_id]['storage_path']
except Exception as e:
raise HTTPException(status_code=404, detail="Space not found")

#function to pull data from remote if remote was provided and if pulse finds diff
try:
repo = git.Repo(space_folder)
except:
except Exception as e:
log.error(e);
repo = git.Repo(os.path.join(space_folder,"repo"))
print(repo.heads)
ahead = 0
behind = 0
# check if the repo has a remote url
try:
#check if the remote origin has commits that haven't been pulled yet
repo_status = repo.git.status(porcelain="v2", branch=True)
ahead_behind_match = re.search(r"#\sbranch\.ab\s\+(\d+)\s-(\d+)", repo_status)
# If no remotes exist or the HEAD is detached, there is no ahead/behind info
if ahead_behind_match:
ahead = int(ahead_behind_match.group(1))
current_hash = repo.head.object.hexsha
o = repo.remotes.origin
o.fetch()
changed = o.refs["master"].object.hexsha != current_hash
if changed:
behind = 1
behind = int(ahead_behind_match.group(2))
pulls = "Repo is {} commits ahead and {} behind.".format(ahead, behind)
except:
pulls = "not available for this space"



hcommit = repo.head.commit
diff_list = hcommit.diff()
difff_list = hcommit.diff(ignore_blank_lines=True, ignore_space_at_eol=True,create_patch=True)
Expand Down Expand Up @@ -152,7 +179,9 @@ def get_git_status(*,space_id: str = Path(None,description="space_id name")):
i+=1
except:
pass
return {'data':toreturn}


return {'data':toreturn, 'status_message':pulls, 'dirty':repo.is_dirty(), 'ahead':ahead, 'behind':behind}

@router.post('/{command}', status_code=200)
def get_git_status(*,space_id: str = Path(None,description="space_id name"),command: str = Path("commit",description="git command to use (commit,pull,push)")):
Expand Down
8 changes: 8 additions & 0 deletions backend/app/webtop-work-space/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
"seed_dependencies": [
"https://github.com/cedricdcc/my_bon_test_crate_2.git"
]
},
"3b1020e07f6640b4bb97766e62c7708a": {
"name": "OSD_datacrate_profile",
"repo_url": "https://github.com/vliz-be-opsci/test_OSD_profilecrate.git",
"logo_url": "https://www.researchobject.org/ro-crate/assets/img/ro-crate-w-text.png",
"description": "test profile to with real shacl data involving the OSD project",
"uuid": "3b1020e07f6640b4bb97766e62c7708a",
"seed_dependencies": ["https://github.com/vliz-be-opsci/test_OSD_profilecrate.git"]
}
}
2 changes: 1 addition & 1 deletion backend/app/webtop-work-space/spaces.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"64e266dfae2b4f34abf0de11ec077e99": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_rocrate_vliz", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "64e266dfae2b4f34abf0de11ec077e99", "remote_url": "", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\64e266dfae2b4f34abf0de11ec077e99"}, "5c64534759534c869ef98422b4ac2ca8": {"storage_path": "C:/Users/cedric/Desktop/no importante\\testuicrate", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "5c64534759534c869ef98422b4ac2ca8", "remote_url": "", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\5c64534759534c869ef98422b4ac2ca8"}}
{"64e266dfae2b4f34abf0de11ec077e99": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_rocrate_vliz", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "64e266dfae2b4f34abf0de11ec077e99", "remote_url": "", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\64e266dfae2b4f34abf0de11ec077e99"}, "5c64534759534c869ef98422b4ac2ca8": {"storage_path": "C:/Users/cedric/Desktop/no importante\\testuicrate", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "5c64534759534c869ef98422b4ac2ca8", "remote_url": "", "workspace_path": "C:\\Users\\cedric\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\5c64534759534c869ef98422b4ac2ca8"}, "c7837176cc6e47dfb55f38708c4fa24f": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\test_osd", "ro_profile": "233ec883a63a4cf8965fb7fab08fe7c5", "uuid": "c7837176cc6e47dfb55f38708c4fa24f", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate.git", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\c7837176cc6e47dfb55f38708c4fa24f"}, "0ce3f86d9bd649c885d7ef715454bb56": {"storage_path": "C:/Users/cedricd/Desktop/test_rocrate_api\\osd_profile_good_test", "ro_profile": "3b1020e07f6640b4bb97766e62c7708a", "uuid": "0ce3f86d9bd649c885d7ef715454bb56", "remote_url": "https://github.com/vliz-be-opsci/test_OSD_datacrate.git", "workspace_path": "C:\\Users\\cedricd\\Documents\\GitHub\\rocrate-maker-fast-api\\backend\\app\\webtop-work-space\\spaces\\0ce3f86d9bd649c885d7ef715454bb56"}}
127 changes: 127 additions & 0 deletions frontend/src/components/datacrate_overview_row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//import some css here
import React, {useState, useEffect} from 'react';
import Badge from '@mui/material/Badge';
import axios from 'axios';
import {BASE_URL_SERVER} from '../App.js';
import ReactLoading from 'react-loading';
import {Button, OverlayTrigger, Popover} from 'react-bootstrap';
import {FaFolderOpen, FaGitAlt, FaCog} from 'react-icons/fa';
import {MdOpenInBrowser} from "react-icons/md";

function Datacrate_overview_row(props) {
//constants
const spacedata = props.spacedata;
const [todisplaydata, setTodisplaydata] = useState({});
const [Loadingrow, setLoadingRow] = useState(true);
console.log(spacedata);
//functions
const popoveropenfilebrowser = (
<Popover id="popover-open">
<Popover.Header as="h3">Open File Browser</Popover.Header>
<Popover.Body>
Click this to <b>open</b> a file <b>explorer</b> at the path of the <b>datacrate location</b>.
You can add files/folders here and these will be incorperated in the ROCrate.
Note that the File <b>explorer</b> will <b>not</b> be <b>focussed</b> on <b>automatically</b>.
</Popover.Body>
</Popover>
);

//function to get shacl data from the spacedata name
const getShaclData = (spacedata) => {
var tosetasdisplaydata = spacedata;
axios.get(BASE_URL_SERVER + 'apiv1/spaces/' + spacedata['name'] + '/annotation/shacl_report')
.then(function (res) {
console.log(res.data);
var shacl_requirements = res.data.shacl_requirements;
console.log(shacl_requirements);

//get the number of shacl errors that are in shacl_requirements
try{
var ammount_violations = shacl_requirements[0]["http://www.w3.org/ns/shacl#result"].length;
console.log(ammount_violations);
tosetasdisplaydata['shacl_violations'] = ammount_violations;
}
catch(error){
console.log(error);
var ammount_violations = 0;
tosetasdisplaydata['shacl_violations'] = ammount_violations;
}
console.log(tosetasdisplaydata);
setTodisplaydata(tosetasdisplaydata);
setLoadingRow(false);
})
}

const BadgeFolder = (props) => {
var ShaclErrors = props.ShaclErrors;
if(ShaclErrors > 0){
return(
<Badge color="error" badgeContent={ShaclErrors}>
<FaFolderOpen size="2em"/>
</Badge>
)
}else{
return(
<Badge color="success" variant="dot">
<FaFolderOpen size="2em"/>
</Badge>
)
}
}

const OpenBrowserSpace = async (spaceid) => {
var spaceid = spaceid;
axios.get(BASE_URL_SERVER+`apiv1/spaces/${spaceid}/content/openexplorer`)
.then(res => {
console.log(res)
})
}



//useEffect
useEffect(() => {
getShaclData(spacedata);
},[]);

//return section
if(Loadingrow){
return(
<></>
)
}else{
return (
<>
<tr>
<td><a href={'/spaces/' + todisplaydata.name }><button className='project_name'>{todisplaydata.truespacename}</button></a></td>
<td>{todisplaydata.trueprofilename}</td>
<td>
<OverlayTrigger trigger={['hover', 'focus']} placement="bottom" overlay={popoveropenfilebrowser}>
<button onClick={() => OpenBrowserSpace(todisplaydata.name)}>
<MdOpenInBrowser></MdOpenInBrowser>
</button>
</OverlayTrigger>
<a href={'/spaces/' + todisplaydata.name + '/all_files'}>
<button>
<BadgeFolder ShaclErrors={todisplaydata.shacl_violations}/>
</button>
</a>
<a href={'/spaces/' + todisplaydata.name + '/git'}>
<button>
<FaGitAlt></FaGitAlt>
</button>
</a>
<a href={'/spaces/' + todisplaydata.name + '/settings'}>
<button>
<FaCog></FaCog>
</button>
</a>
</td>
</tr>
</>
)
}

}

export default Datacrate_overview_row
Loading

0 comments on commit 3a75254

Please sign in to comment.