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

Commit

Permalink
gsoc second objective concepts and mappings diff view
Browse files Browse the repository at this point in the history
gsoc second objective concepts and mappings diff view
  • Loading branch information
hao555sky committed Jul 22, 2017
1 parent bcd0f2d commit b18a62a
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 150 deletions.
48 changes: 5 additions & 43 deletions ocl_web/apps/concepts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,22 +418,7 @@ def get_context_data(self, *args, **kwargs):
if self.request.user.is_authenticated():
context['all_collections'] = api.get_all_collections_for_user(self.request.user.username)

all_sources = _get_org_or_user_sources_list2(self.request, self.owner_id)
# concept_versions = []
# source_concepts = None
# for i in range(len(all_sources)):
# if all_sources[i]['owner_type'] == 'User':
# owner_type = 'users'
# else:
# owner_type = 'orgs'
# source_concepts = self.get_source_concepts(owner_type, all_sources[i]['owner'],
# all_sources[i]['id'])
# for j in range(len(source_concepts)):
# concept_versions.extend(self.get_concept_versions(owner_type, all_sources[i]['owner'], all_sources[i]['id'],
# source_concepts[j]['id']))
#
# all_concepts = api.get('concepts').json()

all_sources = _get_org_or_user_sources_list2(self.request, str(self.request.user))

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

def get(self, request, *args, **kwargs):
print('ConceptHistoryView: get')
self.get_args()
if request.is_ajax():
api = OclApi(self.request, debug=True)
result = api.get(self.owner_type, self.owner_id, 'sources', kwargs.get('source'), 'concepts',
kwargs.get('concept'), 'versions', params={'limit': '0'})
print('result: ', result)
return HttpResponse(json.dumps(result.json()), content_type="application/json")
return super(ConceptHistoryView, self).get(self, *args, **kwargs)

def get_source_concepts(self, owner_type, owner_id, source_id):
api = OclApi(self.request, debug=True)
source_concepts = api.get(owner_type, owner_id, 'sources', source_id, 'concepts').json()
return source_concepts

def get_concept_versions(self, owner_type, owner_id, source_id, concept_id):
api = OclApi(self.request, debug=True)
versions = api.get(owner_type, owner_id, 'sources', source_id, 'concepts', concept_id, 'versions').json()
return versions


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

print("ConceptDiffView ")

def get_context_data(self, *args, **kwargs):
print('ConceptDiffView get_context_data ')
# print('ConceptDiffView get_context_data request: ', self.request)
# print('ConceptDiffView get_context_data args: ', args)
# print('ConceptDiffView get_context_data kwargs: ', kwargs)

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

print('concept_versions: ', concept_versions)
first_concept_version = concept_versions[0].split("/")[1:-1]
second_concept_version = concept_versions[1].split("/")[1:-1]

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

api = OclApi(self.request, debug=True)
concept1 = self.get_concept_details(
self.owner_type, self.owner_id, self.source_id, self.concept_id,
source_version_id=self.source_version_id, concept_version_id=concept_versions[0])
concept2 = self.get_concept_details(
self.owner_type, self.owner_id, self.source_id, self.concept_id,
source_version_id=self.source_version_id, concept_version_id=concept_versions[1])
concept1 = api.get(*first_concept_version).json()
concept2 = api.get(*second_concept_version).json()

context['kwargs'] = self.kwargs
context['concept'] = concept1
context['concept1'] = json.dumps(concept1)
context['concept2'] = json.dumps(concept2)

# print('kwargs: ', context)

return context


Expand Down
3 changes: 3 additions & 0 deletions ocl_web/apps/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def _get_org_or_user_sources_list(**kwargs):
sources = []
oclApi = OclApi(kwargs['initial']['request'], debug=True)
username = str(kwargs['initial']['request'].user)

print("_get_org_or_user_sources_list: kwargs: ", kwargs)

response_user_sources = oclApi.get('users', username, 'sources', params={'limit': 20})
sources.extend([] if response_user_sources.status_code == 404
else [source for source in response_user_sources.json()])
Expand Down
40 changes: 38 additions & 2 deletions ocl_web/apps/mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ast
import re
from django.shortcuts import redirect
from django.http import Http404
from django.http import Http404, HttpResponse
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from django.contrib import messages
Expand All @@ -21,7 +21,7 @@
from .forms import (MappingNewForm, MappingForkForm, MappingEditForm, MappingRetireForm)
from braces.views import LoginRequiredMixin
from libs.ocl import OclApi
from apps.core.views import UserOrOrgMixin, _get_map_type_list
from apps.core.views import UserOrOrgMixin, _get_map_type_list, _get_org_or_user_sources_list2

logger = logging.getLogger('oclweb')

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

all_sources = _get_org_or_user_sources_list2(self.request, str(self.request.user))
context['all_sources'] = all_sources

return context

def get(self, request, *args, **kwargs):
self.get_args()
if request.is_ajax():
api = OclApi(self.request, debug=True)
result = api.get(self.owner_type, self.owner_id, 'sources', kwargs.get('source'), 'mappings',
kwargs.get('mapping'), 'versions', params={'limit': '0'})
return HttpResponse(json.dumps(result.json()), content_type="application/json")
return super(MappingVersionsView, self).get(self, *args, **kwargs)


class MappingDiffView(LoginRequiredMixin, UserOrOrgMixin, MappingReadBaseView):
template_name = "mappings/mappings_diff.html"

def get_context_data(self, *args, **kwargs):

mapping_versions = self.request.GET.getlist('mappingVersion')

first_mapping_version = mapping_versions[0].split("/")[1:-1]
second_mapping_version = mapping_versions[1].split("/")[1:-1]

context = super(MappingDiffView, self).get_context_data(*args, **kwargs)
self.get_args()

api = OclApi(self.request, debug=True)
mapping1 = api.get(*first_mapping_version).json()
mapping2 = api.get(*second_mapping_version).json()

context['kwargs'] = self.kwargs
context['mapping'] = mapping1
context['mapping1'] = json.dumps(mapping1)
context['mapping2'] = json.dumps(mapping2)

return context


class MappingEditView(LoginRequiredMixin, UserOrOrgMixin, MappingFormBaseView):
Expand Down
7 changes: 6 additions & 1 deletion ocl_web/config/users_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
ConceptDetailsView, ConceptMappingsView, ConceptHistoryView, ConceptEditView, ConceptDiffView,
ConceptRetireView, ConceptNewView, ConceptForkView, ConceptDescView, ConceptNameView)
from apps.mappings.views import (
MappingDetailsView, MappingNewView, MappingForkView, MappingEditView, MappingRetireView, MappingVersionsView)
MappingDetailsView, MappingNewView, MappingForkView, MappingEditView, MappingRetireView, MappingVersionsView,
MappingDiffView)
from apps.core.views import ExtraJsonView
from apps.collections.views import CollectionDetailView, CollectionCreateView, CollectionEditView, CollectionAboutView, \
CollectionVersionsView, CollectionConceptsView, CollectionMappingsView, \
Expand Down Expand Up @@ -266,6 +267,10 @@
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
MappingVersionsView.as_view(), name='mapping-versions'),

# /users/:user/sources/:source/mappings/:mapping/diff/
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
MappingDiffView.as_view(), name='mapping-diff-version'),

# /users/:user/sources/:source/mappings/:mapping/edit/
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
MappingEditView.as_view(), name='mapping-edit'),
Expand Down
47 changes: 41 additions & 6 deletions ocl_web/static/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
// alert($scope.selectedFirstConceptVersion);
// };

$scope.getSources = function () {
$scope.getConcepts = function () {

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

Expand All @@ -665,11 +665,9 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
url: url
}).then(function success(response){
$scope.source_concepts = response['data']['items'];
}, function fail(response) {
alert("get concepts fail");
})
};
$scope.getConcepts = function () {
$scope.getVersions = function () {

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

Expand All @@ -678,14 +676,51 @@ app.controller("ConceptVersionsController", function ($scope, $http, $location)
url: concept_versions_url
}).then(function success(response){
$scope.concept_versions = response['data'];
}, function fail(response) {
alert(response.toString());
})
};

// $scope.getSelectedSecondConceptVersion = function () {
// alert($scope.selectedSecondConceptVersion);
// };

$scope.submitCompareForm = function (compareForm, concept_version_diff_url) {
url = concept_version_diff_url + "?conceptVersion=" + $scope.selectedFirstConceptVersion + "&conceptVersion=" +
$scope.selectedSecondConceptVersion;
window.location.href = url;
}
});


app.controller("MappingVersionsController", function ($scope, $http) {

$scope.getMappings = function () {

var url = $scope.selected_source + 'mappings/';

$http({
method: 'GET',
url: url
}).then(function success(response){
$scope.source_mappings = response['data']['items'];
})
};
$scope.getVersions = function () {

var mapping_versions_url = $scope.selected_Mapping + 'history/';

$http({
method: 'GET',
url: mapping_versions_url
}).then(function success(response){
$scope.mapping_versions = response['data'];
})
};

$scope.submitCompareMappingsForm = function (compareMappingsForm, mapping_version_diff_url) {
url = mapping_version_diff_url + "?mappingVersion=" + $scope.selectedFirstMappingVersion + "&mappingVersion=" +
$scope.selectedSecondMappingVersion;
window.location.href = url;
}
});

// Simple function to handle removing member from org
Expand Down
Loading

0 comments on commit b18a62a

Please sign in to comment.