简体   繁体   English

angular js spring boot并添加关联数组的值之一

[英]angular js spring boot and adding one of value of associative array

Im new to using angularjs, javascript and Spring boot. 我刚开始使用angularjs,javascript和Spring boot。 Please help me for this. 请帮我。

I'm trying to show work report rows in attendance page. 我正在尝试在出勤页面显示工作报告行。 When you click a row on one of the staff on a certain date, it shows the work report rows which shows the reports on what a staff did on a day. 当您单击某个日期的某个职员上的一行时,它将显示工作报告行,其中显示有关职员在一天中所做的工作的报告。

Im trying to add the total workreport hours but I cant't add them and showing it on the browser. 我正在尝试添加工作报告的总时数,但我无法添加它们并将其显示在浏览器中。

This is how the webpage looks like(There are FROM & TO calendar to select the attendance data). 网页的外观如下(有FROM&TO日历可以选择出勤数据)。

Attendance Page
-----------------
FROM   TO 

Date        |   Staff  |  Clock In   |  Clock Out  | Working Hours 
---------------------------------------------------------------
2016-09-01  |   Gwen   |    9:00     |    17:00    |  8

2016-09-01  |   Tom    |    9:00     |    18:00    |  8

2016-09-01  |   Mike   |    9:00     |    17:00    |  7

2016-09-02  |   Gwen   |    9:00     |    17:00    |  7

2016-09-02  |   Tom    |    9:00     |    18:00    |  8

2016-09-02  |   Mike   |    9:00     |    17:00    |  7

When you click a row above, it looks like this. 当您单击上方的一行时,它看起来像这样。

Date        |   Staff  |  Clock In   |  Clock Out  | Working Hours 
---------------------------------------------------------------
2016-09-01  |   Gwen   |    9:00     |    17:00    |  8
--------------------------------------------------------------

Title       |  Customer | Project |   Progress Rate | Hours
--------------------------------------------------------------

Sales       |    MAC    | iwatch2 |   50            | 5

HM          |  our firm |    SE   |   70            | 2

Consultant  |  our firm |    SE   |   70            | 1

And I would want to add hours. 我想增加几个小时。 total work report Hours 8 总工作报告时数8

This is the html file and I'm stuck on how to show total work hours for each attendance data's work reports like below. 这是html文件,我被困在如何显示每个出勤数据的工作报告的总工作时间,如下所示。

---------------------------
total work hours  | 8

And this is the part of HTML. 这是HTML的一部分。

<table st-table="attendanceList" st-safe-src="attendanceList" class="table">
<thead>
<tr class="header">
<th st-sort="date">DATE</th>
<th st-sort="staffData.name">STAFF</th>
<th st-sort="clockIn">IN</th>
<th st-sort="clockOut">OUT</th>
<th st-sort="workinghours">WORKHOURS</th>
</tr>
</thead>
<tbody>
<tr ng-repeat-start="attendance in attendanceList"  class="selectable"
      ng-click="showDetail(attendance.id)" ng-class="attendance.id == selectedAttendanceId ? 'selected' : ''">
<td>{{attendance.date | date: "yyyy-MM-dd"}}</td>
<td>{{attendance.staffData.name}}</td>
<td>{{attendance.clockIn | date: "HH:mm:ss"}}</td>
<td>{{attendance.clockOut | date: "HH:mm:ss"}}</td>
<td>{{attendance.workinghours | date: "HH:mm:ss"}}</td>
</tr>
<tr ng-repeat-end ng-show="attendance.id == selectedAttendanceId">
<td colspan="11">
<h5>WORKREPORT</h5>
<table class="table">
<thead>
<tr>
<th>TITLE</th>
<th>CUSTOMER</th>
<th>PROJECT</th>
<th>PROGRESS RATE</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="workreport in workreportMap[attendance.staffDto.id][attendance.date]">
<td>{{workreport.title}}</td>
<td>{{workreport.customer}}</td>
<td>{{workreport.project}}</td>
<td>{{workreport.progress}}</td>
</tr>
<tr>
<td>TOTAL HOURS</td> <td>{{hours}}</td>
</tr>            
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

This is the controller. 这是控制器。 And I'm stuck on adding. 而且我坚持添加。

app.controller('attendanceCtl') ----- app.controller('attendanceCtl')-----

workbenchApp.controller('attendanceCtrl', ['$scope', '$modal', 'MessagesService', 'attendanceFactory','staffFactory', '・・・otherFatories',
    function($scope, $modal, MessagesService, attendanceFactory, staffFactory, otherFactories) {

    $scope.from = new Date($scope.today.getFullYear(), $scope.today.getMonth()-1, $scope.today.getDate());
    $scope.to = new Date($scope.today.getFullYear(), $scope.today.getMonth(), $scope.today.getDate(), 23, 59, 59);

    $scope.isLoading = true;
    $scope.borderDate = editLockFactory.getBorderDate($scope.today);


    getAttendance();

    function getAttendance() {
        $scope.isLoading = true;
        usSpinnerService.spin('attendanceSpinner');
        attendanceFactory.getfromto($scope.from, $scope.to)
        .success(function(attendanceList) {
            $scope.attendanceList = attendanceList;
            $scope.displayedAttendanceList = angular.copy($scope.attendanceList);

            workreportFactory.get($scope.from, $scope.to)
            .success(function(workreportList) {

                $scope.workreportList = workreportList;

                $scope.workreportMap = {};

                for (var i = 0; i < workreportList.length; i++) {

                    var report = workreportList[i];
                    var keydate = report.date;
                    var totalWorktime = 0;

                    if ($scope.workreportMap[report.staffData.id] == null) {
                        $scope.workreportMap[report.staffData.id] = [];
                    }

                    if (($scope.workreportMap[report.staffData.id][keydate] == null) ) {
                        $scope.workreportMap[report.staffData.id][keydate] = [];

                        $scope.workreportMap[report.staffData.id][keydate].push({
                            title: report.title,
                            customer: report.customer,
                            projects: report.projects,
                            progress: report.progress,
                            hours: hours

                        });

                        totalWorktime += report.hours;


                    }else if($scope.workreportMap[report.staffData.id][keydate].length != 0 ){
                        $scope.workreportMap[report.staffData.id][keydate].length+1;
                        //second push for if there are few data(rows for workreport for a person on a day)
                        $scope.workreportMap[report.staffData.id][keydate].push({
                            title: report.title,
                            customer: report.customer,
                            projects: report.projects,
                            progress: report.progress,
                            hours: hours

                        });

                        totalWorktime += report.hours;
                    }
                }//for END

                stopSpinner();

            })
            .error(function(data, status) {
                MessagesService.messages.push({
                    type: 'danger',
                    content: 'ERROR: Status code ' + status
                });
                MessagesService.display = true;
                stopSpinner();
            });

            stopSpinner();
        })
        .error(function(data, status) {
            MessagesService.messages.push({
                type: 'danger',
                content: 'ERROR: Status code ' + status
            });
            MessagesService.display = true;
            stopSpinner();
        });
    }

A variable that sums up the hours like "$scope.totalhours" in the following code could be the solution. 可以使用下面的代码来汇总诸如“ $ scope.totalhours”之类的小时数的变量。 Then at the end of ng-repeat you can print that value out. 然后在ng-repeat结束时,您可以打印出该值。

$scope.totalhours = 0;
for(var i = 0; i<workreportList.length; i++){

    var workreportList = workreportList; $scope.workreportMap = {};    

    if(workreportMap[attendance.staffData.id] == null){
        workreportMap[staffData.id]= [];
    }
    if(workreportMap[staffData.id][attendance.date] == null){
        workreportMap[staffData.id][attendance.date] = [];
    } else if(workreportMap[staffData.id][attendance.date].length != 0){
        workreportMap[staffData.id][attendance.date].length+1;
    }
    $scope.workreportMap[staffData.id][attendance.date].push({
        title: report.title,
        customer: report.customer,
        projects: report.projects,
        progress: report.progress,
        hours: hours
        });
    $scope.totalhours = $scope.totalhours + hours;
}

Note: I also cleared up the two central if statements as they held the same push method twice. 注意:我还清理了两个中央if语句,因为它们两次具有相同的push方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM