-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectProject.html
133 lines (112 loc) · 5.18 KB
/
selectProject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html ng-app="Geneysis" ng-controller="MainController" ng-cloak>
<head>
<meta charset="UTF-8">
<title>Geneysis</title>
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="css/geneysis.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<link href="css/hover.min.css" rel="stylesheet">
</head>
<body>
<div class="select-project">
<h3>Select a project:</h3>
<h5><small style="color:#eee;">Add new project with <i class="fa fa-plus" aria-hidden="true"></i> at bottom.</small></h5>
<hr>
<div class="projects">
<h5 ng-if="projects.length == 0">Oops! Looks like you don't have any projects!</h5>
<div class="project " ng-repeat="project in projects" ng-click="selectProject(project)">
<h5 class="project-name"><strong>{{project.name}}</strong></h5>
<h6 class="project-path">Last Updated: {{project.updated.toLocaleString()}}</h6>
<button type="button" class="select-project-btn"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i></button>
</div>
</div>
<div class="new-project">
<h6>Projects Found: {{projects.length}}</h6>
<button class="add-new-project-btn" ng-init="showNewProjectBox = false" ng-click="showNewProjectForm()"><i class="fa fa-plus" aria-hidden="true"></i></button>
</div>
</div>
<div class="new-project-background" ng-click="handleNewProjectClick($event)" ng-show="showNewProjectBox">
<div class="new-project-box">
<form name="newForm">
<div class="form-group" ng-cladd="{'has-error':newForm.$invalid,'has-success':newForm.$valid}">
<label class="new-project-input-label control-label" for="new-project-input">New Project Name</label>
<input name="name" type="text" class="new-project-input" id="new-project-input" ng-init="newProjectName = ''" ng-model="newProjectName" ng-pattern="/^[^\\\/\ ]+$/">
<span style="color:#eee;position:relative;font-size:10px;margin-left:10px;top:-10px;"
class="help-block" ng-if="newForm.$invalid">No spaces or slashes please!</span>
</div>
</form>
<button style="position:absolute;bottom:5px;right:5px;"
class="btn btn-sm btn-success pull-right" ng-disabled="newForm.$invalid || newProjectName.length == 0" ng-click="createProject()">Create and Open</button>
</div>
</div>
</body>
<script src="node_modules/angular/angular.min.js"></script>
<script src="js/electangular.js"></script>
<script>
"use strict";
var app = angular.module('Geneysis', [require('angular-animate'), require('angular-ui-bootstrap'), 'electangular']);
const geneysis = require('./js/geneysis.js');
app.controller("MainController", ["$rootScope","$scope","ipc", function($rootScope,$scope, ipc) {
$scope.projects = [];
$scope.wd = "";
ipc.send({task:"get_projects"});
$rootScope.$on('electron-msg', (event, msg) => {
switch(msg.task) {
case "projects":
for (let i = 0; i < msg.projects.length; i++) {
msg.projects[i].created = new Date(msg.projects[i].created * 1000)
msg.projects[i].updated = new Date(msg.projects[i].updated * 1000)
}
function compare(a,b) {
if (a.updated > b.updated)
return -1;
if (a.updated < b.updated)
return 1;
return 0;
}
msg.projects.sort(compare);
console.log(msg.projects);
$scope.projects = msg.projects;
$scope.wd = msg.wd;
$scope.$apply();
break;
}
});
$scope.selectProject = function(proj) {
ipc.send({task:"open_project", project:proj });
}
$scope.showNewProjectForm = function() {
$scope.showNewProjectBox = true;
setTimeout(function() {
document.getElementById("new-project-input").focus();
},50);
}
$scope.handleNewProjectClick = function($event) {
if ($event.target.className == "new-project-background") {
$scope.showNewProjectBox = false;
}
}
$scope.createProject = function() {
let valid = true;
for (let project of $scope.projects) {
if (project.name == $scope.newProjectName) {
valid = false;
}
}
if ($scope.newForm.$valid && $scope.newProjectName.length > 0 && valid) {
$scope.newProjectName = $scope.newProjectName.replace(" ","")
geneysis.createNewProject($scope.wd + $scope.newProjectName, function(results,err) {
let project = JSON.parse(results[0])
project.created = new Date(project.created * 1000)
project.updated = new Date(project.updated * 1000)
$scope.selectProject(project);
});
}
else if (!valid) {
alert("That name is already taken!");
}
}
}]);
</script>
</html>