如何在HTML的for循环中将不同的Datepicker数据分配给不同的行?

时间:2019-07-05 07:56:56

标签: javascript jquery html jquery-ui-datepicker

我目前正在从事这个项目。在日期列下,我传递开始和结束日期并将其与进度一起存储在db中,例如dev,cr fix等。我想做的是制作一个页面,其中用户名下方列出的故事具有其自己的进度日期选择器,例如: 如果我必须在他的故事汇总器上分配标记,则表示进度。然后,我将选择开始和结束日期以及进度,然后单击提交。我希望在检查日期选择器中使用其特定颜色对其进行更新。检查日期选择器仅用于显示当前故事下的用户进度。每个用户及其故事都有不同的进展。

我所做的同样是获取故事的开始和结束日期,其ID和进度,并将其存储在数据库中。然后,我使用json将开发人员的名称,id,开始日期和结束日期以及进度从控制器传递到datepicker的脚本。问题在于每个日期选择器都显示所有故事和用户的综合进度。请同样帮我。我正在提供相同的HTML,js代码和视图。

This is my project's page image for the same.

这是我的HTML和Javascript代码:

  $(document).ready(function() {
      var nDates = {};
      var data  = JSON.parse('{{ d1|escapejs }}');
      var stat = JSON.parse('{{ d2|escapejs }}');
      var jid = JSON.parse('{{ d3|escapejs }}');
      var arr1=[];
      var arr2=[];
      var arr3=[];
      var j_id=[];
      var dev_name=[]
      // alert(data);
      for(i in data){
        for(j in data[i]){
          for(k in data[i][j]){
            if(data[i][j].hasOwnProperty(k)){
                arr1.push(k);
                arr2.push(data[i][j][k]);
                dev_name.push(i);
            }
          }
        }
      }
      console.log(dev_name)
      for(i in stat){
        for(j in stat[i]){
          arr3.push(stat[i][j]);
        }
      }

      for(i in jid){
        for(j in jid[i]){
          j_id.push(jid[i][j]);
        }
      }
      console.log(j_id)

      for(var i =0 ;i<arr1.length;i++){
          var day = 1000*60*60*24;
          date1 = new Date(arr1[i]);
          date2 = new Date(arr2[i]);
          var diff = (date2.getTime()- date1.getTime())/day;
          for(var r=0;r<=diff; r++)
          {
             var xx = date1.getTime()+day*r;
             var yy = new Date(xx);
             z=(yy.getFullYear()+"/"+(yy.getMonth()+1)+"/"+yy.getDate());
             if(arr3[i]=='Dev'){
               nDates[new Date(z)] = 1;
             }
             if(arr3[i]=='CR Fix'){
               nDates[new Date(z)] = 2;
             }
             if(arr3[i]=='QA Support'){
               nDates[new Date(z)] = 3;
             }
             if(arr3[i]=='Release Support'){
               nDates[new Date(z)] = 4;
             }
          }
      }


      $('.datepicker1').datepicker({
          dateFormat: 'yy-mm-dd',
          minDate: new Date({{a}},{{b}}-1,{{c}}),
          maxDate: new Date({{d}},{{e}}-1,{{f}}),
          beforeShowDay: function (date) {
              var dev1 = nDates[date];
              var color="";
              if (dev1) {
                  if(dev1==1)
                    color='dev';
                  if(dev1==2)
                    color='cr';
                  if(dev1==3)
                    color='qa';
                  if(dev1==4)
                    color='rel';
                  return [true, color, 'Tooltip text'];
              }
              else {
                  return [false, '', ''];
              }
          }
      });
  });
 <div class="content">
      <div class="row">
        <div class="col-md-12">
          <div class="card">
            <div class="card-body">
              <div class="table-responsive">
                <table class="table" id="tab2">
                  <thead class=" text-primary">
                    <!-- <th>Check</th> -->
                    <th>Name</th>
                    <th>Jira ID</th>
                    <th>Overall Status</th>
                    <th>Estimate</th>
                    <th>Actual</th>
                    <th>Date</th>
                    <th>Progress</th>
                    <th>Check</th>
                    <!-- <th>Check</th> -->
                  </thead>
                  <tbody>
                    {% for i in data %}
                    <tr>
                      <td><b>{{ i.name }}</b></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td>
                          <div class='box green'></div>-- Dev<br>
                          <div class='box red'></div>-- CR Fix<br>
                          <div class='box black'></div>-- QA Support<br>
                          <div class='box purple'></div>-- Release Support<br>
                      </td>
                    </tr>
                    {% for j in list1 %}
                      {% if forloop.counter == forloop.parentloop.counter %}
                        {% for k in j %}
                    <form method="GET" id="se">
                    <tr>
                      <td>{{ k.0 }}</td>
                      <td>{{ k.1 }}</td>
                      <td>
                        <select class="chosen" name="sel">
                          <option>{{ k.3 }}</option>
                          <option>Live</option>
                          <option>In Progress</option>
                          <option>HTML Done</option>
                          <option>PHP Done</option>
                          <option>API Done</option>
                          <option>QA</option>
                          <option>Pending Development</option>
                          <option>Blocked</option>
                          <option>BLocked on API</option>
                          <option>Blocked on HTML</option>
                          <option>Blocked on Mock</option>
                          <option>Blocked on Spec</option>
                          <option>Not Needed</option>
                          <option>Next Sprint</option>
                          <option>Duplicate</option>
                          <option>CR</option>
                        </select>
                        <input type="hidden" name="jid" value="{{ k.1 }}">
                        <input type="hidden" name="name1" value="{{ i.name }}">
                        <input type="button" name="as" value="Assign">
                      </td>
                      <td>{{ k.2 }}</td>
                      <td></td>
                      <td><input type="text" name="startdate" placeholder="Start Date" class="datepicker">
                          <input type="text" name="enddate" placeholder="End Date" class="datepicker"></td>
                      <td>
                        <select class="chosen" name="prg">
                          <option>Dev</option>
                          <option>CR Fix</option>
                          <option>QA Support</option>
                          <option>Release Support</option>
                        </select>
                        <input type="hidden" name="j1" value="{{ k.1 }}">
                        <input type="hidden" name="name2" value="{{ i.name }}">
                        <input type="submit" value="Submit">
                      </td>
                      <td><input type="text" placeholder="Check Status" class="datepicker1"></td>
                    </tr>
                  </form>
                        {% endfor %}
                      {% endif %}
                    {% endfor %}
                    {% endfor %}
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

这是我对此的看法:

def qaprg(request):
id1 = request.session['id']
data = register.objects.filter(roles='dev')
list1=[]
j=0
p = product.objects.get(id=id1)
x = p.sprint_start_date
y = p.sprint_dev_end_date
x=str(x)
a,b,c = x.split('-')
y=str(y)
d,e,f = y.split('-')
a=int(a)
b=int(b)
c=int(c)
d=int(d)
e=int(e)
f=int(f)

list2={}
# m=0
for i1 in data:
    st1 = story.objects.filter(sprint_id=id1,dev_java=i1.name) | story.objects.filter(sprint_id=id1,dev_php=i1.name) | story.objects.filter(sprint_id=id1,dev_html=i1.name) | story.objects.filter(sprint_id=id1,dev_qa=i1.name)
    n=0
    list2[i1.name]={}
    for j1 in st1:
        if prg.objects.filter(s_id=id1,jd=j1.jira,dname=i1.name).exists()==True:
            p1 = prg.objects.filter(s_id=id1,jd=j1.jira,dname=i1.name)
            for k1 in p1:
                list2[i1.name][n]={}
                list2[i1.name][n][str(k1.sdate)]=str(k1.edate)
                n+=1
    # m+=1
jd1=json.dumps(list2)

list3={}
m=0
for i2 in data:
    st1 = story.objects.filter(sprint_id=id1,dev_java=i2.name) | story.objects.filter(sprint_id=id1,dev_php=i2.name) | story.objects.filter(sprint_id=id1,dev_html=i2.name) | story.objects.filter(sprint_id=id1,dev_qa=i2.name)
    n=0
    list3[m]={}
    for j2 in st1:
        if prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name).exists()==True:
            p1 = prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name)
            for k2 in p1:
                list3[m][n]=k2.status
                n+=1
    m+=1
jd2=json.dumps(list3)

list4={}
m=0
for i2 in data:
    st1 = story.objects.filter(sprint_id=id1,dev_java=i2.name) | story.objects.filter(sprint_id=id1,dev_php=i2.name) | story.objects.filter(sprint_id=id1,dev_html=i2.name) | story.objects.filter(sprint_id=id1,dev_qa=i2.name)
    n=0
    list4[m]={}
    for j2 in st1:
        if prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name).exists()==True:
            p1 = prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name)
            for k2 in p1:
                list4[m][n]=k2.jd
                n+=1
    m+=1
jd3=json.dumps(list4)


for i in data:
    list1.append([])
    k=0
    st = story.objects.filter(sprint_id=id1,dev_java=i.name) | story.objects.filter(sprint_id=id1,dev_php=i.name) | story.objects.filter(sprint_id=id1,dev_html=i.name) | story.objects.filter(sprint_id=id1,dev_qa=i.name)
    for r in st:
        list1[j].append([])
        list1[j][k].append(r.story_name)
        list1[j][k].append(r.jira)
        if r.dev_java==i.name:
            list1[j][k].append(r.javas)
            list1[j][k].append(r.jstat)
        elif r.dev_php==i.name:
            list1[j][k].append(r.phps)
            list1[j][k].append(r.pstat)
        elif r.dev_html==i.name:
            list1[j][k].append(r.htmls)
            list1[j][k].append(r.hstat)
        elif r.dev_qa==i.name:
            list1[j][k].append(r.qas)
            list1[j][k].append(r.qstat)
        k+=1
    j+=1

if request.method=='GET':
    if 'as' in request.GET:
        s = request.GET.get('sel')
        j = request.GET.get('jid')
        n1 = request.GET.get('name1')
        p = story.objects.get(sprint_id=id1,jira = j)
        if p.dev_java == n1:
            p.jstat = s
        elif p.dev_php == n1:
            p.pstat = s
        elif p.dev_html == n1:
            p.hstat = s
        elif p.dev_qa == n1:
            p.qstat = s
        p.save()
        return redirect('qaprg')

    if 'startdate' in request.GET:
        stdate = request.GET.get('startdate')
        endate = request.GET.get('enddate')
        prog = request.GET.get('prg')
        j = request.GET.get('j1')
        n2 = request.GET.get('name2')
        day = np.busday_count(stdate,endate)
        st = story.objects.filter(sprint_id=id1,dev_java=n2,jira=j) | story.objects.filter(sprint_id=id1,dev_php=n2,jira=j) | story.objects.filter(sprint_id=id1,dev_html=n2,jira=j) | story.objects.filter(sprint_id=id1,dev_qa=n2,jira=j)
        z = prg(s_id=id1,jd=j,sdate=stdate,edate=endate,days=day,status=prog,dname=n2)
        z.save()

        list2={}
        for i1 in data:
            st1 = story.objects.filter(sprint_id=id1,dev_java=i1.name) | story.objects.filter(sprint_id=id1,dev_php=i1.name) | story.objects.filter(sprint_id=id1,dev_html=i1.name) | story.objects.filter(sprint_id=id1,dev_qa=i1.name)
            n=0
            list2[i1.name]={}
            for j1 in st1:
                if prg.objects.filter(s_id=id1,jd=j1.jira,dname=i1.name).exists()==True:
                    p1 = prg.objects.filter(s_id=id1,jd=j1.jira,dname=i1.name)
                    for k1 in p1:
                        list2[i1.name][n]={}
                        list2[i1.name][n][str(k1.sdate)]=str(k1.edate)
                        n+=1

        jd1=json.dumps(list2)

        list3={}
        m=0
        for i2 in data:
            st1 = story.objects.filter(sprint_id=id1,dev_java=i2.name) | story.objects.filter(sprint_id=id1,dev_php=i2.name) | story.objects.filter(sprint_id=id1,dev_html=i2.name) | story.objects.filter(sprint_id=id1,dev_qa=i2.name)
            n=0
            list3[m]={}
            for j2 in st1:
                if prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name).exists()==True:
                    p1 = prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name)
                    for k2 in p1:
                        list3[m][n]=k2.status
                        n+=1
            m+=1
        jd2=json.dumps(list3)

        list4={}
        m=0
        for i2 in data:
            st1 = story.objects.filter(sprint_id=id1,dev_java=i2.name) | story.objects.filter(sprint_id=id1,dev_php=i2.name) | story.objects.filter(sprint_id=id1,dev_html=i2.name) | story.objects.filter(sprint_id=id1,dev_qa=i2.name)
            n=0
            list4[m]={}
            for j2 in st1:
                if prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name).exists()==True:
                    p1 = prg.objects.filter(s_id=id1,jd=j2.jira,dname=i2.name)
                    for k2 in p1:
                        list4[m][n]=k2.jd
                        n+=1
            m+=1
        jd3=json.dumps(list4)

        return redirect('qaprg')

return(render(request,'qaprg.html/',{'data':data,'list1':list1,'p':p,'a':a,'b':b,'c':c,'d':d,'e':e,'f':f,'d1':jd1,'d2':jd2,'d3':jd3}))

0 个答案:

没有答案