From d97b6d1a4dd045c85d3899fe2c586fbc6e73d975 Mon Sep 17 00:00:00 2001 From: cedricdecruw <30471340+cedricdcc@users.noreply.github.com> Date: Tue, 3 May 2022 12:02:24 +0200 Subject: [PATCH] added requirements.txt for docker composing cleaned up packages for frontend to reduce size of load * fixed issue where # were added in the rocrate-metadata.json when trying to add annotation to a child node of a file --- backend/app/model/rocrategit.py | 14 +- backend/app/routers/APIV1/annotation.py | 2 +- backend/app/routers/APIV1/spaces.py | 353 +++++++++++++----------- backend/requirements.txt | 13 + frontend/package-lock.json | 122 -------- frontend/package.json | 3 - frontend/src/pages/git.js | 35 ++- 7 files changed, 239 insertions(+), 303 deletions(-) create mode 100644 backend/requirements.txt diff --git a/backend/app/model/rocrategit.py b/backend/app/model/rocrategit.py index 3e83c84..b6e6d48 100644 --- a/backend/app/model/rocrategit.py +++ b/backend/app/model/rocrategit.py @@ -414,6 +414,7 @@ def create_blank_node_by_id(self, file_id=str, node_type=str, uri_predicate=str) #add uri predicate to the item with value of nw blacnk node @id item[uri_predicate] = {"@id":new_uuid_blank_node} #write the new graph to the metadata file + log.debug(data) self._write_metadata_datacrate(data) return new_blank_node @@ -459,14 +460,9 @@ def add_predicates_by_id(self,toadd_dict_list=list, file_id=str): test = shclh.ShapesInfoGraph(path_shacl) shacldata = test.full_shacl_graph_dict() data = self._read_metadata_datacrate() - try: - myrocrate = ROCrate(self.storage_path) - data_entities = myrocrate.data_entities - except Exception as e: - log.error(f'error when loading rocrate data via rocrate python lib: {e}') - log.exception(e) - data_entities = data['@graph'] - log.debug(data_entities) + + data_entities = data['@graph'] + log.debug(data_entities) #convert the chacl file to have all the properties per node id @@ -548,7 +544,7 @@ def add_predicates_by_id(self,toadd_dict_list=list, file_id=str): if uri_name not in chacl_URI_list: warnings.append("non shacl defined constraint metadata has been added: "+ uri_name) - ## implement annotation in the data is found , send warning message is annotation title not found in constraints ## + ## implement annotation in the data is found , send warning message is annotation title not found in constraints ## ## write back to metadata file and return metadata.json file try: myrocrate.write(self.storage_path) diff --git a/backend/app/routers/APIV1/annotation.py b/backend/app/routers/APIV1/annotation.py index df1c845..69af613 100644 --- a/backend/app/routers/APIV1/annotation.py +++ b/backend/app/routers/APIV1/annotation.py @@ -56,7 +56,7 @@ class AnnotationModel(BaseModel): value : str = Field(None, description = "Value linked to the URI predicate name chosen") class BlankModel(BaseModel): - URI_predicate_name : str = Field(None, description = "Name of the URI that will be added, must be part of the RO-crate profile provided metadata predicates;") + URI_predicate_name : str = Field(None, description = "Name of the URI that will be added, must be part of the RO-crate profile provided metadata predicates") node_type : str = Field(None, description = "Type of the node that will be added.") class AnnotationsModel(BaseModel): diff --git a/backend/app/routers/APIV1/spaces.py b/backend/app/routers/APIV1/spaces.py index 511100c..6e528cf 100644 --- a/backend/app/routers/APIV1/spaces.py +++ b/backend/app/routers/APIV1/spaces.py @@ -85,177 +85,204 @@ class DeleteContentModel(BaseModel): #TODO: function that reads the shacl contraint file and gets the right properties for an accordingly chosen schema target class (@type in rocrate metadata.json) def complete_metadata_crate(source_path_crate): - - ## get all the file_ids with their metadata ## - #open up the metadata.json file - with open(os.path.join(source_path_crate, 'ro-crate-metadata.json')) as json_file: - datao = json.load(json_file) + try: + ## get all the file_ids with their metadata ## + #open up the metadata.json file + with open(os.path.join(source_path_crate, 'ro-crate-metadata.json')) as json_file: + datao = json.load(json_file) + + #get all the node ids where the type is not a file + node_ids = [] + for node in datao['@graph']: + if node['@type'] != 'File': + node_ids.append(node) - #check if the ids from relation are present in the json file - all_meta_ids_data = [] - for id in datao['@graph']: - toappend_id = {} - toappand_data_values = [] - for key_id, value_id in id.items(): - if key_id != "@id": - toappand_data_values.append({key_id:value_id}) - toappend_id[id['@id']] = toappand_data_values - all_meta_ids_data.append(toappend_id) - - log.debug(f"all metadata ids of data: {all_meta_ids_data}") - - #make pre meta ids - all_ids_pre_new_doc = [] - for id in datao['@graph']: - all_ids_pre_new_doc.append(id['@id']) - - - ## start from fresh file with metadata template ## - with open(os.path.join(os.getcwd(),'app',"webtop-work-space",'ro-crate-metadata.json')) as json_file: - data = json.load(json_file) + + #check if the ids from relation are present in the json file + all_meta_ids_data = [] + for id in datao['@graph']: + toappend_id = {} + toappand_data_values = [] + # if first character is # in the @id then delete the # + if id['@id'][0] == '#': + id['@id'] = id['@id'][1:] + for key_id, value_id in id.items(): + if key_id != "@id": + toappand_data_values.append({key_id:value_id}) + toappend_id[id['@id']] = toappand_data_values + all_meta_ids_data.append(toappend_id) - log.debug(f"data from rocrate: {data}") - - - ## add data to the fresh file ## - relation = [] - for root, dirs, files in os.walk(source_path_crate, topdown=False): - if ".git" not in root: - log.info(f'root == {root}') - for name in files: - log.info(f'file == {name}') - if name != ".git": - if root.split(source_path_crate)[-1] == "": - parent_folder = "" - relative_path = "./" - else: - relative_path = root.split(source_path_crate)[-1] - parent_folder = relative_path.split(os.path.sep)[-1] - relation.append({'parent_folder':parent_folder,"relative_path":relative_path,"name":name}) - all_ids = [] - for x in relation: - #log.debug(x) - all_ids.append(x["name"]) - - #check if the ids from relation are present in the json file - all_meta_ids = [] - for id in data['@graph']: - all_meta_ids.append(id['@id']) - #log.debug(id['@id']) - for i in all_ids: - if i not in all_meta_ids: - #log.debug("not present: "+ i) - #check if parent is present in the file + log.debug(f"all metadata ids of data: {all_meta_ids_data}") + + #make pre meta ids + all_ids_pre_new_doc = [] + for id in datao['@graph']: + all_ids_pre_new_doc.append(id['@id']) + + + ## start from fresh file with metadata template ## + with open(os.path.join(os.getcwd(),'app',"webtop-work-space",'ro-crate-metadata.json')) as json_file: + data = json.load(json_file) - def add_folder_path(path_folder): - toaddppaths = path_folder.split("\\") - previous = "./" - for toadd in toaddppaths: - if str(toadd+"/") not in all_meta_ids: - if toadd != "": - data['@graph'].append({'@id':toadd+"/", '@type':"Dataset", 'hasPart':[]}) - # add ro right haspart - for ids in data['@graph']: - if ids['@id'] == previous: - try: - ids['hasPart'].append({'@id':toadd+"/"}) - except: - ids['hasPart'] = [] - ids['hasPart'].append({'@id':toadd+"/"}) - all_meta_ids.append(str(toadd+"/")) - if toadd == "": - previous = './' - else: - previous = toadd+"/" - - - for checkparent in relation: - if checkparent['name'] == i: - if str(checkparent['parent_folder']+"/") not in all_meta_ids: - if checkparent['parent_folder'] != "": - #make the parent_folder in ids - data['@graph'].append({'@id':checkparent['parent_folder']+"/", '@type':"Dataset", 'hasPart':[]}) - #check if folder has no parent - if len(checkparent['relative_path'].split("\\")) == 2: - checkparentpath = checkparent['relative_path'].split("\\") - log.debug(f"splitted relative path: {checkparentpath}") + log.debug(f"data from rocrate: {data}") + + #add all the node ids to the data + for i in node_ids: + data['@graph'].append(i) + + ## add data to the fresh file ## + relation = [] + for root, dirs, files in os.walk(source_path_crate, topdown=False): + if ".git" not in root: + log.info(f'root == {root}') + for name in files: + log.info(f'file == {name}') + if name != ".git": + if root.split(source_path_crate)[-1] == "": + parent_folder = "" + relative_path = "./" + else: + relative_path = root.split(source_path_crate)[-1] + parent_folder = relative_path.split(os.path.sep)[-1] + relation.append({'parent_folder':parent_folder,"relative_path":relative_path,"name":name}) + all_ids = [] + for x in relation: + #log.debug(x) + all_ids.append(x["name"]) + + #check if the ids from relation are present in the json file + all_meta_ids = [] + for id in data['@graph']: + all_meta_ids.append(id['@id']) + #log.debug(id['@id']) + for i in all_ids: + if i not in all_meta_ids: + #log.debug("not present: "+ i) + #check if parent is present in the file + + def add_folder_path(path_folder): + toaddppaths = path_folder.split("\\") + previous = "./" + for toadd in toaddppaths: + if str(toadd+"/") not in all_meta_ids: + if toadd != "": + data['@graph'].append({'@id':toadd+"/", '@type':"Dataset", 'hasPart':[]}) + # add ro right haspart for ids in data['@graph']: - if ids['@id'] == './': - if {'@id':checkparent['relative_path'].split("\\")[-1]+"/"} not in ids['hasPart']: - ids['hasPart'].append({'@id':checkparent['relative_path'].split("\\")[-1]+"/"}) + if ids['@id'] == previous: + try: + ids['hasPart'].append({'@id':toadd+"/"}) + except: + ids['hasPart'] = [] + ids['hasPart'].append({'@id':toadd+"/"}) + all_meta_ids.append(str(toadd+"/")) + if toadd == "": + previous = './' + else: + previous = toadd+"/" + + + for checkparent in relation: + if checkparent['name'] == i: + if str(checkparent['parent_folder']+"/") not in all_meta_ids: + if checkparent['parent_folder'] != "": + #make the parent_folder in ids + data['@graph'].append({'@id':checkparent['parent_folder']+"/", '@type':"Dataset", 'hasPart':[]}) + #check if folder has no parent + if len(checkparent['relative_path'].split("\\")) == 2: + checkparentpath = checkparent['relative_path'].split("\\") + log.debug(f"splitted relative path: {checkparentpath}") + for ids in data['@graph']: + if ids['@id'] == './': + if {'@id':checkparent['relative_path'].split("\\")[-1]+"/"} not in ids['hasPart']: + ids['hasPart'].append({'@id':checkparent['relative_path'].split("\\")[-1]+"/"}) + + add_folder_path(checkparent['relative_path']) + #add the non present id to the folder haspart + for ids in data['@graph']: + if checkparent['parent_folder'] == "": + if ids['@id'] == "."+checkparent['parent_folder']+"/": + ids['hasPart'].append({'@id':i}) + else: + if ids['@id'] == checkparent['parent_folder']+"/": + ids['hasPart'].append({'@id':i}) + #add the id to the @graph + data['@graph'].append({'@id':i, '@type':"File"}) + #add id to ./ folder if necessary + + #add the references to the @graph + for i in all_ids_pre_new_doc: + #log.info(f"meta id i: {i}") + valid=validators.url(i) + if valid: + #log.info(f"valid url: {i}") + #add i to the graph + for id in data['@graph']: + if id["@id"] == './': + id["hasPart"].append({'@id':i}) + data['@graph'].append({'@id':i, '@type':"File"}) + + ## add file_ids metadata correspondingly ## + for ids in data['@graph']: + # check if the first character fo the ids["@id "] is a # , if so remove this char + if ids["@id"][0] == "#": + log.info(ids["@id"]) + ids["@id"] = ids["@id"][1:] + log.info(ids["@id"]) + for tocheck_id in all_meta_ids_data: + log.info(ids['@id']) + if ids['@id'] in str(tocheck_id.keys()): + log.info(tocheck_id) + for dict_single_metadata in tocheck_id[ids['@id']]: + for key_dict_single_meta, value_dcit_sinle_meta in dict_single_metadata.items(): + if key_dict_single_meta not in ids.keys(): + log.debug(f"key of single file metadata: {key_dict_single_meta}") + ids[key_dict_single_meta] = value_dcit_sinle_meta + + #remove duplicates + seen_ids = [] + for ids in data['@graph']: + if ids['@id'] in seen_ids: + log.info("duplicate id found: "+ids['@id']) + data['@graph'].remove(ids) + else: + seen_ids.append(ids['@id']) - add_folder_path(checkparent['relative_path']) - #add the non present id to the folder haspart - for ids in data['@graph']: - if checkparent['parent_folder'] == "": - if ids['@id'] == "."+checkparent['parent_folder']+"/": - ids['hasPart'].append({'@id':i}) + #remove duplicates from hasPart + new_graph = [] + seen_ids = [] + for ids in data['@graph']: + if ids['@id'] not in seen_ids: + seen_ids.append(ids['@id']) + + # if ids has hasPart check hasparts + if 'hasPart' in ids: + new_hasparts = [] + seen_hasparts = [] + for haspart in ids['hasPart']: + if haspart['@id'] in seen_hasparts: + log.info("duplicate id found in hasparts of id: "+ haspart["@id"] + ids['@id']) else: - if ids['@id'] == checkparent['parent_folder']+"/": - ids['hasPart'].append({'@id':i}) - #add the id to the @graph - data['@graph'].append({'@id':i, '@type':"File"}) - #add id to ./ folder if necessary - - #add the references to the @graph - for i in all_ids_pre_new_doc: - log.info(f"meta id i: {i}") - valid=validators.url(i) - if valid: - log.info(f"valid url: {i}") - #add i to the graph - for id in data['@graph']: - if id["@id"] == './': - id["hasPart"].append({'@id':i}) - data['@graph'].append({'@id':i, '@type':"File"}) - - ## add file_ids metadata correspondingly ## - for ids in data['@graph']: - for tocheck_id in all_meta_ids_data: - if ids['@id'] in str(tocheck_id.keys()): - for dict_single_metadata in tocheck_id[ids['@id']]: - for key_dict_single_meta, value_dcit_sinle_meta in dict_single_metadata.items(): - if key_dict_single_meta not in ids.keys(): - log.debug(f"key of single file metadata: {key_dict_single_meta}") - ids[key_dict_single_meta] = value_dcit_sinle_meta - - #remove duplicates - seen_ids = [] - for ids in data['@graph']: - if ids['@id'] in seen_ids: - log.info("duplicate id found: "+ids['@id']) - data['@graph'].remove(ids) - else: - seen_ids.append(ids['@id']) - - #remove duplicates from hasPart - new_graph = [] - seen_ids = [] - for ids in data['@graph']: - if ids['@id'] not in seen_ids: - seen_ids.append(ids['@id']) - - # if ids has hasPart check hasparts - if 'hasPart' in ids: - new_hasparts = [] - seen_hasparts = [] - for haspart in ids['hasPart']: - if haspart['@id'] in seen_hasparts: - log.info("duplicate id found in hasparts of id: "+ haspart["@id"] + ids['@id']) - else: - seen_hasparts.append(haspart['@id']) - new_hasparts.append(haspart) - ids['hasPart'] = new_hasparts - new_graph.append(ids) - - data["@graph"] = new_graph - - #write the rocrate file back - with open(os.path.join(source_path_crate, 'ro-crate-metadata.json'), 'w') as json_file: - json.dump(data, json_file) + seen_hasparts.append(haspart['@id']) + new_hasparts.append(haspart) + ids['hasPart'] = new_hasparts + new_graph.append(ids) - return data + data["@graph"] = new_graph + + + + #write the rocrate file back + with open(os.path.join(source_path_crate, 'ro-crate-metadata.json'), 'w') as json_file: + json.dump(data, json_file) + return data + + except Exception as e: + log.error(f"error: {e}") + log.exception(e) + + def check_space_name(spacename): with open(Locations().join_abs_path('spaces.json'), "r+")as file: data = json.load(file) diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..a2a9080 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,13 @@ +aiohttp==3.8.1 +fastapi==0.75.2 +numpy==1.18.1 +pydantic==1.9.0 +pyshacl==0.19.0 +pytest==7.1.2 +python-dotenv==0.20.0 +PyYAML==6.0 +rdflib==6.1.1 +requests==2.23.0 +rocrate==0.5.5 +SPARQLWrapper==2.0.0 +validators==0.18.2 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c11b835..695a835 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1441,11 +1441,6 @@ "@emotion/utils": "^1.1.0" } }, - "@emotion/stylis": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/@emotion/stylis/-/stylis-0.8.5.tgz", - "integrity": "sha512-h6KtPihKFn3T9fuIrwvXXUOwlx3rfUvfZIcP5a6rh8Y7zjE3O06hT5Ss4S/YI1AYhuZ1kjaE/5EaOOI2NqSylQ==" - }, "@emotion/unitless": { "version": "0.7.5", "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", @@ -3312,11 +3307,6 @@ "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" }, - "attr-accept": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-2.2.2.tgz", - "integrity": "sha512-7prDjvt9HmqiZ0cl5CRjtS84sEyhsHP2coDkaZKRKVfCDo9s7iw7ChVmar78Gu9pC4SoR/28wFu/G5JJhTnqEg==" - }, "autoprefixer": { "version": "9.8.8", "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.8.8.tgz", @@ -3541,23 +3531,6 @@ "@babel/helper-define-polyfill-provider": "^0.3.0" } }, - "babel-plugin-styled-components": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-2.0.7.tgz", - "integrity": "sha512-i7YhvPgVqRKfoQ66toiZ06jPNA3p6ierpfUuEWxNF+fV27Uv5gxBkf8KZLHUCc1nFA9j6+80pYoIpqCeyW3/bA==", - "requires": { - "@babel/helper-annotate-as-pure": "^7.16.0", - "@babel/helper-module-imports": "^7.16.0", - "babel-plugin-syntax-jsx": "^6.18.0", - "lodash": "^4.17.11", - "picomatch": "^2.3.0" - } - }, - "babel-plugin-syntax-jsx": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", - "integrity": "sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY=" - }, "babel-plugin-syntax-object-rest-spread": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", @@ -4243,11 +4216,6 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==" }, - "camelize": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.0.tgz", - "integrity": "sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs=" - }, "caniuse-api": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz", @@ -4828,11 +4796,6 @@ "postcss": "^7.0.5" } }, - "css-color-keywords": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz", - "integrity": "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU=" - }, "css-color-names": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", @@ -4916,16 +4879,6 @@ "resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz", "integrity": "sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w==" }, - "css-to-react-native": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.0.0.tgz", - "integrity": "sha512-Ro1yETZA813eoyUp2GDBhG2j+YggidUmzO1/v9eYBKR2EHVEniE2MI/NqpTQ954BMpTPZFsGNPm46qFB9dpaPQ==", - "requires": { - "camelize": "^1.0.0", - "css-color-keywords": "^1.0.0", - "postcss-value-parser": "^4.0.2" - } - }, "css-tree": { "version": "1.0.0-alpha.37", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.37.tgz", @@ -6741,21 +6694,6 @@ } } }, - "file-selector": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/file-selector/-/file-selector-0.2.4.tgz", - "integrity": "sha512-ZDsQNbrv6qRi1YTDOEWzf5J2KjZ9KMI1Q2SGeTkCJmNNW25Jg4TW4UMcmoqcg4WrAyKRcpBXdbWRxkfrOzVRbA==", - "requires": { - "tslib": "^2.0.3" - }, - "dependencies": { - "tslib": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" - } - } - }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", @@ -12049,16 +11987,6 @@ "scheduler": "^0.20.2" } }, - "react-dropzone": { - "version": "11.4.2", - "resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-11.4.2.tgz", - "integrity": "sha512-ocYzYn7Qgp0tFc1gQtUTOaHHSzVTwhWHxxY+r7cj2jJTPfMTZB5GWSJHdIVoxsl+EQENpjJ/6Zvcw0BqKZQ+Eg==", - "requires": { - "attr-accept": "^2.2.1", - "file-selector": "^0.2.2", - "prop-types": "^15.7.2" - } - }, "react-error-overlay": { "version": "6.0.9", "resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz", @@ -12122,11 +12050,6 @@ "react-router": "6.0.2" } }, - "react-script-tag": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/react-script-tag/-/react-script-tag-1.1.2.tgz", - "integrity": "sha512-4oR9ntvGfX4igiP77vK310ru5Oa77xO7CeYB3Xi9lu0qsikpGpK1Kq1WMFocvy8U4fQFq8ovtrZS/8adfCziFw==" - }, "react-scripts": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-4.0.3.tgz", @@ -13238,11 +13161,6 @@ "safe-buffer": "^5.0.1" } }, - "shallowequal": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz", - "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==" - }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", @@ -13837,46 +13755,6 @@ "schema-utils": "^2.7.0" } }, - "styled-components": { - "version": "5.3.5", - "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.5.tgz", - "integrity": "sha512-ndETJ9RKaaL6q41B69WudeqLzOpY1A/ET/glXkNZ2T7dPjPqpPCXXQjDFYZWwNnE5co0wX+gTCqx9mfxTmSIPg==", - "requires": { - "@babel/helper-module-imports": "^7.0.0", - "@babel/traverse": "^7.4.5", - "@emotion/is-prop-valid": "^1.1.0", - "@emotion/stylis": "^0.8.4", - "@emotion/unitless": "^0.7.4", - "babel-plugin-styled-components": ">= 1.12.0", - "css-to-react-native": "^3.0.0", - "hoist-non-react-statics": "^3.0.0", - "shallowequal": "^1.1.0", - "supports-color": "^5.5.0" - }, - "dependencies": { - "hoist-non-react-statics": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", - "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", - "requires": { - "react-is": "^16.7.0" - } - }, - "react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "requires": { - "has-flag": "^3.0.0" - } - } - } - }, "stylehacks": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-4.0.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index a07a491..d8533e3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -25,14 +25,11 @@ "react-bootstrap": "^2.0.2", "react-chartjs-2": "^4.1.0", "react-dom": "^17.0.2", - "react-dropzone": "^11.4.2", "react-gh-like-diff": "^2.0.2", "react-icons": "^4.3.1", "react-loading": "^2.0.3", "react-router-dom": "^6.0.2", - "react-script-tag": "^1.1.2", "react-scripts": "4.0.3", - "styled-components": "^5.3.5", "web-vitals": "^1.0.1" }, "scripts": { diff --git a/frontend/src/pages/git.js b/frontend/src/pages/git.js index dc60934..a4af5e2 100644 --- a/frontend/src/pages/git.js +++ b/frontend/src/pages/git.js @@ -26,16 +26,30 @@ export default class GitPage extends React.Component { this.state = { message: "commit", Loading: false, - SpaceId: "" + SpaceId: "", + behind: "", + ahead: "" } this.updateMessage = this.updateMessage.bind(this); this.setLoading = this.setLoading.bind(this); this.setSpaceId = this.setSpaceId.bind(this); + this.setbehind = this.setbehind.bind(this); + this.setahead = this.setahead.bind(this); } componentDidMount() { const SpaceId = window.location.href.split("/spaces/")[1].split("/git")[0]; this.setSpaceId(SpaceId); + //perform axiosrequest that will get the git status of the space + axios.get(BASE_URL_SERVER+`apiv1/spaces/${SpaceId}/git/status`) + .then(response => { + if(response.data.behind > 0){ + this.setbehind("disabled"); + } + if(response.data.ahead > 0){ + this.setahead("disabled"); + } + }) } setSpaceId(id) { @@ -44,6 +58,18 @@ export default class GitPage extends React.Component { }) } + setbehind(behind){ + this.setState({ + behind: behind + }) + } + + setahead(ahead){ + this.setState({ + ahead: ahead + }) + } + updateMessage(message) { this.setState({ message: message @@ -56,6 +82,8 @@ export default class GitPage extends React.Component { }); } + + sendPush(){ console.log('pushing to git repo'); console.log(this.state.SpaceId); @@ -82,7 +110,6 @@ export default class GitPage extends React.Component { } render() { - const message = this.state.message; let todisplay; if(message == "commit"){ @@ -93,7 +120,6 @@ export default class GitPage extends React.Component { todisplay = ; console.log(todisplay); } - if(this.state.Loading){ return(
@@ -103,13 +129,12 @@ export default class GitPage extends React.Component {
) } - if(this.state.Loading == false){ return (

- +