Skip to content

Commit d498ffc

Browse files
committed
fix(overlap): Issue angular-gantt#606 - Overlap Style Missing on Added Task
Handle task add. Added timeout similar to data change handler. Added demo control.
1 parent 5be739d commit d498ffc

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

demo/app/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ <h4 class="panel-title">
211211
</div>
212212
</div>
213213

214+
<div class="form-group text-center">
215+
<label class="control-label"><i class="fa fa-database"></i>Add Overlapping Task</label><br>
216+
<div class="form-group">
217+
<input type="number" ng-model="options.targetDataAddRowIndex" step="1" min="0" class="form-control" placeholder="Row Index"/>
218+
<button class="btn btn-default" ng-click="addOverlapTaskToTargetRowIndex()">Add</button>
219+
</div>
220+
</div>
214221

215222
</div>
216223
</div>

demo/app/scripts/controllers/main.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ angular.module('angularGanttDemoApp')
163163
enabled: true,
164164
conflictChecker: true
165165
},
166+
targetDataAddRowIndex: undefined,
166167
canDraw: function(event) {
167168
var isLeftMouseButton = event.button === 0 || event.button === 1;
168169
return $scope.options.draw && !$scope.options.readOnly && isLeftMouseButton;
@@ -367,6 +368,35 @@ angular.module('angularGanttDemoApp')
367368
$scope.data = [];
368369
};
369370

371+
// Add data to target row index
372+
$scope.addOverlapTaskToTargetRowIndex = function() {
373+
var targetDataAddRowIndex = parseInt($scope.options.targetDataAddRowIndex);
374+
375+
if (targetDataAddRowIndex) {
376+
var targetRow = $scope.data[$scope.options.targetDataAddRowIndex];
377+
378+
if (targetRow && targetRow.tasks && targetRow.tasks.length > 0) {
379+
var firstTaskInRow = targetRow.tasks[0];
380+
var copiedColor = firstTaskInRow.color;
381+
var firstTaskEndDate = firstTaskInRow.to.toDate();
382+
var overlappingFromDate = new Date(firstTaskEndDate);
383+
384+
overlappingFromDate.setDate(overlappingFromDate.getDate() - 1);
385+
386+
var overlappingToDate = new Date(overlappingFromDate);
387+
388+
overlappingToDate.setDate(overlappingToDate.getDate() + 7);
389+
390+
targetRow.tasks.push({
391+
"name": "Overlapping",
392+
"from": overlappingFromDate,
393+
"to": overlappingToDate,
394+
"color": copiedColor
395+
});
396+
}
397+
}
398+
};
399+
370400

371401
// Visual two way binding.
372402
$scope.live = {};

src/plugins/overlap.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@
137137
handleOverlaps(oldRow.tasks);
138138
}
139139
});
140+
141+
api.tasks.on.add(scope, function(task) {
142+
// TODO: Mimicked functionality from api.data.on.change to defer until element creation, but not ideal. Refactor necessary to raise 'add' event after task is fully drawn.
143+
$timeout(function() {
144+
if (scope.global) {
145+
var rows = task.row.rowsManager.rows;
146+
handleGlobalOverlaps(rows);
147+
} else {
148+
handleOverlaps(task.row.tasks);
149+
}
150+
});
151+
});
140152
}
141153
}
142154
};

0 commit comments

Comments
 (0)