Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit b18a62a

Browse files
committed
gsoc second objective concepts and mappings diff view
gsoc second objective concepts and mappings diff view
1 parent bcd0f2d commit b18a62a

8 files changed

Lines changed: 285 additions & 150 deletions

File tree

ocl_web/apps/concepts/views.py

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,7 @@ def get_context_data(self, *args, **kwargs):
418418
if self.request.user.is_authenticated():
419419
context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)
420420

421-
all_sources = _get_org_or_user_sources_list2(self.request, self.owner_id)
422-
# concept_versions = []
423-
# source_concepts = None
424-
# for i in range(len(all_sources)):
425-
# if all_sources[i]['owner_type'] == 'User':
426-
# owner_type = 'users'
427-
# else:
428-
# owner_type = 'orgs'
429-
# source_concepts = self.get_source_concepts(owner_type, all_sources[i]['owner'],
430-
# all_sources[i]['id'])
431-
# for j in range(len(source_concepts)):
432-
# concept_versions.extend(self.get_concept_versions(owner_type, all_sources[i]['owner'], all_sources[i]['id'],
433-
# source_concepts[j]['id']))
434-
#
435-
# all_concepts = api.get('concepts').json()
436-
421+
all_sources = _get_org_or_user_sources_list2(self.request, str(self.request.user))
437422

438423
# Set the context
439424
context['kwargs'] = self.kwargs
@@ -449,60 +434,37 @@ def get_context_data(self, *args, **kwargs):
449434
return context
450435

451436
def get(self, request, *args, **kwargs):
452-
print('ConceptHistoryView: get')
453437
self.get_args()
454438
if request.is_ajax():
455439
api = OclApi(self.request, debug=True)
456440
result = api.get(self.owner_type, self.owner_id, 'sources', kwargs.get('source'), 'concepts',
457441
kwargs.get('concept'), 'versions', params={'limit': '0'})
458-
print('result: ', result)
459442
return HttpResponse(json.dumps(result.json()), content_type="application/json")
460443
return super(ConceptHistoryView, self).get(self, *args, **kwargs)
461444

462-
def get_source_concepts(self, owner_type, owner_id, source_id):
463-
api = OclApi(self.request, debug=True)
464-
source_concepts = api.get(owner_type, owner_id, 'sources', source_id, 'concepts').json()
465-
return source_concepts
466-
467-
def get_concept_versions(self, owner_type, owner_id, source_id, concept_id):
468-
api = OclApi(self.request, debug=True)
469-
versions = api.get(owner_type, owner_id, 'sources', source_id, 'concepts', concept_id, 'versions').json()
470-
return versions
471-
472445

473446
class ConceptDiffView(LoginRequiredMixin, UserOrOrgMixin, ConceptReadBaseView):
474447
template_name = "concepts/concept_diff.html"
475448

476-
print("ConceptDiffView ")
477-
478449
def get_context_data(self, *args, **kwargs):
479-
print('ConceptDiffView get_context_data ')
480-
# print('ConceptDiffView get_context_data request: ', self.request)
481-
# print('ConceptDiffView get_context_data args: ', args)
482-
# print('ConceptDiffView get_context_data kwargs: ', kwargs)
483450

484451
concept_versions = self.request.GET.getlist('conceptVersion')
485452

486-
print('concept_versions: ', concept_versions)
453+
first_concept_version = concept_versions[0].split("/")[1:-1]
454+
second_concept_version = concept_versions[1].split("/")[1:-1]
487455

488456
context = super(ConceptDiffView, self).get_context_data(*args, **kwargs)
489457
self.get_args()
490458

491459
api = OclApi(self.request, debug=True)
492-
concept1 = self.get_concept_details(
493-
self.owner_type, self.owner_id, self.source_id, self.concept_id,
494-
source_version_id=self.source_version_id, concept_version_id=concept_versions[0])
495-
concept2 = self.get_concept_details(
496-
self.owner_type, self.owner_id, self.source_id, self.concept_id,
497-
source_version_id=self.source_version_id, concept_version_id=concept_versions[1])
460+
concept1 = api.get(*first_concept_version).json()
461+
concept2 = api.get(*second_concept_version).json()
498462

499463
context['kwargs'] = self.kwargs
500464
context['concept'] = concept1
501465
context['concept1'] = json.dumps(concept1)
502466
context['concept2'] = json.dumps(concept2)
503467

504-
# print('kwargs: ', context)
505-
506468
return context
507469

508470

ocl_web/apps/core/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ def _get_org_or_user_sources_list(**kwargs):
223223
sources = []
224224
oclApi = OclApi(kwargs['initial']['request'], debug=True)
225225
username = str(kwargs['initial']['request'].user)
226+
227+
print("_get_org_or_user_sources_list: kwargs: ", kwargs)
228+
226229
response_user_sources = oclApi.get('users', username, 'sources', params={'limit': 20})
227230
sources.extend([] if response_user_sources.status_code == 404
228231
else [source for source in response_user_sources.json()])

ocl_web/apps/mappings/views.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import ast
88
import re
99
from django.shortcuts import redirect
10-
from django.http import Http404
10+
from django.http import Http404, HttpResponse
1111
from django.views.generic import TemplateView
1212
from django.views.generic.edit import FormView
1313
from django.contrib import messages
@@ -21,7 +21,7 @@
2121
from .forms import (MappingNewForm, MappingForkForm, MappingEditForm, MappingRetireForm)
2222
from braces.views import LoginRequiredMixin
2323
from libs.ocl import OclApi
24-
from apps.core.views import UserOrOrgMixin, _get_map_type_list
24+
from apps.core.views import UserOrOrgMixin, _get_map_type_list, _get_org_or_user_sources_list2
2525

2626
logger = logging.getLogger('oclweb')
2727

@@ -199,8 +199,44 @@ def get_context_data(self, *args, **kwargs):
199199
api = OclApi(self.request, debug=True, facets=True)
200200
context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)
201201

202+
all_sources = _get_org_or_user_sources_list2(self.request, str(self.request.user))
203+
context['all_sources'] = all_sources
204+
202205
return context
203206

207+
def get(self, request, *args, **kwargs):
208+
self.get_args()
209+
if request.is_ajax():
210+
api = OclApi(self.request, debug=True)
211+
result = api.get(self.owner_type, self.owner_id, 'sources', kwargs.get('source'), 'mappings',
212+
kwargs.get('mapping'), 'versions', params={'limit': '0'})
213+
return HttpResponse(json.dumps(result.json()), content_type="application/json")
214+
return super(MappingVersionsView, self).get(self, *args, **kwargs)
215+
216+
217+
class MappingDiffView(LoginRequiredMixin, UserOrOrgMixin, MappingReadBaseView):
218+
template_name = "mappings/mappings_diff.html"
219+
220+
def get_context_data(self, *args, **kwargs):
221+
222+
mapping_versions = self.request.GET.getlist('mappingVersion')
223+
224+
first_mapping_version = mapping_versions[0].split("/")[1:-1]
225+
second_mapping_version = mapping_versions[1].split("/")[1:-1]
226+
227+
context = super(MappingDiffView, self).get_context_data(*args, **kwargs)
228+
self.get_args()
229+
230+
api = OclApi(self.request, debug=True)
231+
mapping1 = api.get(*first_mapping_version).json()
232+
mapping2 = api.get(*second_mapping_version).json()
233+
234+
context['kwargs'] = self.kwargs
235+
context['mapping'] = mapping1
236+
context['mapping1'] = json.dumps(mapping1)
237+
context['mapping2'] = json.dumps(mapping2)
238+
239+
return context
204240

205241

206242
class MappingEditView(LoginRequiredMixin, UserOrOrgMixin, MappingFormBaseView):

ocl_web/config/users_urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
ConceptDetailsView, ConceptMappingsView, ConceptHistoryView, ConceptEditView, ConceptDiffView,
2525
ConceptRetireView, ConceptNewView, ConceptForkView, ConceptDescView, ConceptNameView)
2626
from apps.mappings.views import (
27-
MappingDetailsView, MappingNewView, MappingForkView, MappingEditView, MappingRetireView, MappingVersionsView)
27+
MappingDetailsView, MappingNewView, MappingForkView, MappingEditView, MappingRetireView, MappingVersionsView,
28+
MappingDiffView)
2829
from apps.core.views import ExtraJsonView
2930
from apps.collections.views import CollectionDetailView, CollectionCreateView, CollectionEditView, CollectionAboutView, \
3031
CollectionVersionsView, CollectionConceptsView, CollectionMappingsView, \
@@ -266,6 +267,10 @@
266267
url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/history/$', # pylint: disable=C0301
267268
MappingVersionsView.as_view(), name='mapping-versions'),
268269

270+
# /users/:user/sources/:source/mappings/:mapping/diff/
271+
url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/diff/$', # pylint: disable=C0301
272+
MappingDiffView.as_view(), name='mapping-diff-version'),
273+
269274
# /users/:user/sources/:source/mappings/:mapping/edit/
270275
url(r'^(?P<user>[a-zA-Z0-9\-\.]+)/sources/(?P<source>[a-zA-Z0-9\-\.]+)/mappings/(?P<mapping>[a-zA-Z0-9\-\.]+)/edit/$', # pylint: disable=C0301
271276
MappingEditView.as_view(), name='mapping-edit'),

ocl_web/static/js/project.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
656656
// alert($scope.selectedFirstConceptVersion);
657657
// };
658658

659-
$scope.getSources = function () {
659+
$scope.getConcepts = function () {
660660

661661
var url = $scope.selected_source + 'concepts/';
662662

@@ -665,11 +665,9 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
665665
url: url
666666
}).then(function success(response){
667667
$scope.source_concepts = response['data']['items'];
668-
}, function fail(response) {
669-
alert("get concepts fail");
670668
})
671669
};
672-
$scope.getConcepts = function () {
670+
$scope.getVersions = function () {
673671

674672
var concept_versions_url = $scope.selected_concept + 'history/';
675673

@@ -678,14 +676,51 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
678676
url: concept_versions_url
679677
}).then(function success(response){
680678
$scope.concept_versions = response['data'];
681-
}, function fail(response) {
682-
alert(response.toString());
683679
})
684680
};
685681

686682
// $scope.getSelectedSecondConceptVersion = function () {
687683
// alert($scope.selectedSecondConceptVersion);
688684
// };
685+
686+
$scope.submitCompareForm = function (compareForm, concept_version_diff_url) {
687+
url = concept_version_diff_url + "?conceptVersion=" + $scope.selectedFirstConceptVersion + "&conceptVersion=" +
688+
$scope.selectedSecondConceptVersion;
689+
window.location.href = url;
690+
}
691+
});
692+
693+
694+
app.controller("MappingVersionsController", function ($scope, $http) {
695+
696+
$scope.getMappings = function () {
697+
698+
var url = $scope.selected_source + 'mappings/';
699+
700+
$http({
701+
method: 'GET',
702+
url: url
703+
}).then(function success(response){
704+
$scope.source_mappings = response['data']['items'];
705+
})
706+
};
707+
$scope.getVersions = function () {
708+
709+
var mapping_versions_url = $scope.selected_Mapping + 'history/';
710+
711+
$http({
712+
method: 'GET',
713+
url: mapping_versions_url
714+
}).then(function success(response){
715+
$scope.mapping_versions = response['data'];
716+
})
717+
};
718+
719+
$scope.submitCompareMappingsForm = function (compareMappingsForm, mapping_version_diff_url) {
720+
url = mapping_version_diff_url + "?mappingVersion=" + $scope.selectedFirstMappingVersion + "&mappingVersion=" +
721+
$scope.selectedSecondMappingVersion;
722+
window.location.href = url;
723+
}
689724
});
690725

691726
// Simple function to handle removing member from org

0 commit comments

Comments
 (0)