Skip to content

Commit

Permalink
feat: repl.it integration for Python projects (#305)
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Lane <dale.lane@uk.ibm.com>
  • Loading branch information
dalelane committed May 9, 2020
1 parent 4f16f0f commit f26c4fc
Show file tree
Hide file tree
Showing 26 changed files with 1,546 additions and 333 deletions.
6 changes: 6 additions & 0 deletions public/app.js
Expand Up @@ -187,6 +187,12 @@
templateUrl: 'static/components-<%= VERSION %>/python/python.html',
controllerAs: 'vm'
})
.state('mlproject_python_local', {
url: '/mlproject/:userId/:projectId/pythonlocal',
controller: 'PythonLocalController',
templateUrl: 'static/components-<%= VERSION %>/pythonlocal/python.html',
controllerAs: 'vm'
})
.state('mlproject_appinventor', {
url: '/mlproject/:userId/:projectId/appinventor',
controller: 'AppInventorController',
Expand Down
20 changes: 4 additions & 16 deletions public/components/python/python.controller.js
Expand Up @@ -14,12 +14,6 @@
var vm = this;
vm.authService = authService;

$scope.projectId = $stateParams.projectId;
$scope.userId = $stateParams.userId;

$scope.functionType = 'classify';

$scope.testsource = 'local';
$scope.testdata = {
text : 'The text that you want to test',
storetext : 'The text that you want to store',
Expand All @@ -29,12 +23,9 @@
label : 'label'
};

$scope.setSource = function (source) {
$scope.testsource = source;
};
$scope.setFunctionType = function (type) {
$scope.functionType = type;
};

$scope.projectId = $stateParams.projectId;
$scope.userId = $stateParams.userId;

authService.getProfileDeferred()
.then(function (profile) {
Expand Down Expand Up @@ -63,10 +54,6 @@
.then(function (resp) {
if (resp) {
$scope.scratchkey = resp[0];

if (!$scope.scratchkey.model && $scope.project.type === 'text') {
$scope.functionType = 'store';
}
}
})
.catch(function (err) {
Expand All @@ -75,5 +62,6 @@
status : err.status
};
});

}
}());
5 changes: 5 additions & 0 deletions public/components/python/python.css
@@ -1,3 +1,8 @@
.modelguidance .strongemphasis {
font-weight: bold;
color: #3078b4;
}

.pythoncodebox {
font-size: 0.7em;
background: #ffffff;
Expand Down
479 changes: 182 additions & 297 deletions public/components/python/python.html

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions public/components/pythonlocal/python.controller.js
@@ -0,0 +1,79 @@
(function () {

angular
.module('app')
.controller('PythonLocalController', PythonLocalController);

PythonLocalController.$inject = [
'authService', 'projectsService', 'scratchkeysService',
'$stateParams', '$scope'
];

function PythonLocalController(authService, projectsService, scratchkeysService, $stateParams, $scope) {

var vm = this;
vm.authService = authService;

$scope.projectId = $stateParams.projectId;
$scope.userId = $stateParams.userId;

$scope.functionType = 'classify';

$scope.testsource = 'local';
$scope.testdata = {
text : 'The text that you want to test',
storetext : 'The text that you want to store',
imagefile : 'my-test-image.jpg',
imageurl : 'https://www.site-on-the-internet.com/image.jpg',
fields : [],
label : 'label'
};

$scope.setSource = function (source) {
$scope.testsource = source;
};
$scope.setFunctionType = function (type) {
$scope.functionType = type;
};

authService.getProfileDeferred()
.then(function (profile) {
vm.profile = profile;

return projectsService.getProject($scope.projectId, $scope.userId, profile.tenant);
})
.then(function (project) {
$scope.project = project;
if (project.labels && project.labels.length > 0) {
$scope.testdata.label = project.labels[0];
}

if (project.type === 'numbers') {
return projectsService.getFields($scope.projectId, $scope.userId, vm.profile.tenant);
}
else {
return;
}
})
.then(function (fields) {
$scope.fields = fields;

return scratchkeysService.getScratchKeys($scope.project.id, $scope.userId, vm.profile.tenant);
})
.then(function (resp) {
if (resp) {
$scope.scratchkey = resp[0];

if (!$scope.scratchkey.model && $scope.project.type === 'text') {
$scope.functionType = 'store';
}
}
})
.catch(function (err) {
$scope.failure = {
message : err.data.error,
status : err.status
};
});
}
}());

0 comments on commit f26c4fc

Please sign in to comment.