| @@ -332,7 +332,7 @@ | |||||
| </div> | </div> | ||||
| <!-- 任务状态 --> | <!-- 任务状态 --> | ||||
| <div class="two wide column padding0" style="padding-left: 2.2rem !important;"> | <div class="two wide column padding0" style="padding-left: 2.2rem !important;"> | ||||
| <span class="job-status" id="{{.JobID}}" data-repopath="{{$.RepoRelPath}}" data-jobid="{{.JobID}}"> | |||||
| <span class="job-status" id="{{.JobID}}" data-repopath="{{$.RepoRelPath}}" data-jobid="{{.JobID}}" data-version="{{.VersionName}}"> | |||||
| <span><i id="{{.JobID}}-icon" style="vertical-align: middle;" class="{{.Status}}"></i><span id="{{.JobID}}-text" style="margin-left: 0.4em;font-size: 12px;">{{.Status}}</span></span> | <span><i id="{{.JobID}}-icon" style="vertical-align: middle;" class="{{.Status}}"></i><span id="{{.JobID}}-text" style="margin-left: 0.4em;font-size: 12px;">{{.Status}}</span></span> | ||||
| </span> | </span> | ||||
| </div> | </div> | ||||
| @@ -441,6 +441,8 @@ | |||||
| {{template "base/footer" .}} | {{template "base/footer" .}} | ||||
| <script> | <script> | ||||
| console.log({{.Tasks}}) | |||||
| // 调试和评分新开窗口 | // 调试和评分新开窗口 | ||||
| function stop(obj) { | function stop(obj) { | ||||
| if (obj.style.color != "rgb(204, 204, 204)") { | if (obj.style.color != "rgb(204, 204, 204)") { | ||||
| @@ -490,11 +492,12 @@ | |||||
| $(".job-status").each((index, job) => { | $(".job-status").each((index, job) => { | ||||
| const jobID = job.dataset.jobid; | const jobID = job.dataset.jobid; | ||||
| const repoPath = job.dataset.repopath; | const repoPath = job.dataset.repopath; | ||||
| $.get(`/api/v1/repos/${repoPath}/modelarts/train-job/${jobID}`, (data) => { | |||||
| const versionname = job.dataset.version | |||||
| $.get(`/api/v1/repos/${repoPath}/modelarts/train-job/${jobID}?version_name=${versionname}`, (data) => { | |||||
| console.log(data) | |||||
| const duration = data.JobDuration | const duration = data.JobDuration | ||||
| const jobID = data.JobID | const jobID = data.JobID | ||||
| let train_duration = runtime(duration) | |||||
| $('#duration-'+jobID).text(train_duration) | |||||
| $('#duration-'+jobID).text(duration) | |||||
| }) | }) | ||||
| }) | }) | ||||
| @@ -507,17 +510,18 @@ | |||||
| $(".job-status").each((index, job) => { | $(".job-status").each((index, job) => { | ||||
| const jobID = job.dataset.jobid; | const jobID = job.dataset.jobid; | ||||
| const repoPath = job.dataset.repopath; | const repoPath = job.dataset.repopath; | ||||
| const versionname = job.dataset.version | |||||
| if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED' | if (job.textContent.trim() == 'IMAGE_FAILED' || job.textContent.trim() == 'SUBMIT_FAILED' || job.textContent.trim() == 'DELETE_FAILED' | ||||
| || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED' | || job.textContent.trim() == 'KILLED' || job.textContent.trim() == 'COMPLETED' || job.textContent.trim() == 'FAILED' | ||||
| || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') { | || job.textContent.trim() == 'CANCELED' || job.textContent.trim() == 'LOST') { | ||||
| return | return | ||||
| } | } | ||||
| $.get(`/api/v1/repos/${repoPath}/modelarts/train-job/${jobID}`, (data) => { | |||||
| $.get(`/api/v1/repos/${repoPath}/modelarts/train-job/${jobID}?version_name=${versionname}`, (data) => { | |||||
| const jobID = data.JobID | const jobID = data.JobID | ||||
| const status = data.JobStatus | const status = data.JobStatus | ||||
| const duration = data.JobDuration | const duration = data.JobDuration | ||||
| $('#duration-'+jobID).text(duration) | |||||
| if (status != job.textContent.trim()) { | if (status != job.textContent.trim()) { | ||||
| $('#' + jobID+'-icon').removeClass().addClass(status) | $('#' + jobID+'-icon').removeClass().addClass(status) | ||||
| $('#' + jobID+ '-text').text(status) | $('#' + jobID+ '-text').text(status) | ||||
| @@ -526,8 +530,7 @@ | |||||
| if(status==="RUNNING"){ | if(status==="RUNNING"){ | ||||
| $('#model-debug-'+jobID).removeClass('disabled') | $('#model-debug-'+jobID).removeClass('disabled') | ||||
| $('#model-debug-'+jobID).addClass('blue') | $('#model-debug-'+jobID).addClass('blue') | ||||
| let train_duration = runtime(duration) | |||||
| $('#duration-'+jobID).text(train_duration) | |||||
| // $('#duration-'+jobID).text(duration) | |||||
| } | } | ||||
| if(status!=="RUNNING"){ | if(status!=="RUNNING"){ | ||||
| @@ -541,7 +544,7 @@ | |||||
| $('#model-delete-'+jobID).removeClass('red') | $('#model-delete-'+jobID).removeClass('red') | ||||
| $('#model-delete-'+jobID).addClass('disabled') | $('#model-delete-'+jobID).addClass('disabled') | ||||
| } | } | ||||
| if(status=="KILLED" || status=="FAILED" || status=="KILLING"){ | |||||
| if(status=="KILLED" || status=="FAILED" || status=="KILLING" || status=="COMPLETED"){ | |||||
| $('#stop-model-debug-'+jobID).removeClass('blue') | $('#stop-model-debug-'+jobID).removeClass('blue') | ||||
| $('#stop-model-debug-'+jobID).addClass('disabled') | $('#stop-model-debug-'+jobID).addClass('disabled') | ||||
| $('#model-delete-'+jobID).removeClass('disabled') | $('#model-delete-'+jobID).removeClass('disabled') | ||||
| @@ -136,7 +136,10 @@ td, th { | |||||
| transform: translateY(-6px); | transform: translateY(-6px); | ||||
| border-right: 1px solid #dfe1e6; | border-right: 1px solid #dfe1e6; | ||||
| } | } | ||||
| .text-width80{ | |||||
| width: 100px; | |||||
| line-height: 30px; | |||||
| } | |||||
| </style> | </style> | ||||
| <div class="repository"> | <div class="repository"> | ||||
| {{template "repo/header" .}} | {{template "repo/header" .}} | ||||
| @@ -155,8 +158,8 @@ td, th { | |||||
| <div style="float: right;"> | <div style="float: right;"> | ||||
| <a class="ti-action-menu-item">创建模型</a> | <a class="ti-action-menu-item">创建模型</a> | ||||
| <a class="ti-action-menu-item" href="{{$.RepoLink}}/modelarts/train-job/{{.JobID}}/create_version?version_name={{.VersionName}}">修改</a> | <a class="ti-action-menu-item" href="{{$.RepoLink}}/modelarts/train-job/{{.JobID}}/create_version?version_name={{.VersionName}}">修改</a> | ||||
| <a class="ti-action-menu-item">停止</a> | |||||
| <a class="ti-action-menu-item" style="color: #FF4D4F;">删除</a> | |||||
| <a class="ti-action-menu-item" onclick="stopVersion({{.VersionName}})">停止</a> | |||||
| <a class="ti-action-menu-item" onclick="deleteVersion({{.VersionName}})" style="color: #FF4D4F;">删除</a> | |||||
| </div> | </div> | ||||
| <div class="ac-display-inblock title_text acc-margin-bottom"> | <div class="ac-display-inblock title_text acc-margin-bottom"> | ||||
| @@ -164,10 +167,10 @@ td, th { | |||||
| <span class="cti-mgRight-sm"> 当前版本:{{.VersionName}}</span> | <span class="cti-mgRight-sm"> 当前版本:{{.VersionName}}</span> | ||||
| <span class="cti-mgRight-sm"> 父版本:{{.FatherVersionName}}</span> | <span class="cti-mgRight-sm"> 父版本:{{.FatherVersionName}}</span> | ||||
| <span class="cti-mgRight-sm ac-text-normal title_text">状态: | <span class="cti-mgRight-sm ac-text-normal title_text">状态: | ||||
| <span><i id="icon" style="vertical-align: middle;" class="{{.Status}}"></i><span id="text" style="margin-left: 0.4em;font-size: 12px;">{{.Status}}</span></span> | |||||
| <span id="{{.VersionName}}-status-span"><i id="icon" style="vertical-align: middle;" class="{{.Status}}"></i><span id="text" style="margin-left: 0.4em;font-size: 12px;">{{.Status}}</span></span> | |||||
| </span> | </span> | ||||
| <span class="ac-text-normal title_text">运行时间:</span> | <span class="ac-text-normal title_text">运行时间:</span> | ||||
| <span class="cti-mgRight-sm uc-accordionTitle-black">{{.TrainJobDuration}}</span> | |||||
| <span class="cti-mgRight-sm uc-accordionTitle-black" id="{{.VersionName}}-duration-span">{{.TrainJobDuration}}</span> | |||||
| <span data-tooltip="刷新" data-inverted="" onclick="refreshStatus({{.VersionName}})"><i class="redo icon redo-color"></i></span> | <span data-tooltip="刷新" data-inverted="" onclick="refreshStatus({{.VersionName}})"><i class="redo icon redo-color"></i></span> | ||||
| </div> | </div> | ||||
| @@ -191,7 +194,7 @@ td, th { | |||||
| <table class="ti-form"> | <table class="ti-form"> | ||||
| <tbody class="ti-text-form"> | <tbody class="ti-text-form"> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 任务名称 | 任务名称 | ||||
| </td> | </td> | ||||
| @@ -202,18 +205,18 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 状态 | 状态 | ||||
| </td> | </td> | ||||
| <td class="ti-text-form-content"> | <td class="ti-text-form-content"> | ||||
| <div class="text-span text-span-w"> | |||||
| <div class="text-span text-span-w" id="{{.VersionName}}-status"> | |||||
| {{.Status}} | {{.Status}} | ||||
| </div> | </div> | ||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 运行版本 | 运行版本 | ||||
| </td> | </td> | ||||
| @@ -224,7 +227,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 开始时间 | 开始时间 | ||||
| </td> | </td> | ||||
| @@ -235,18 +238,18 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 运行时间 | 运行时间 | ||||
| </td> | </td> | ||||
| <td class="ti-text-form-content"> | <td class="ti-text-form-content"> | ||||
| <div class="text-span text-span-w"> | |||||
| <div class="text-span text-span-w" id="{{.VersionName}}-duration"> | |||||
| {{.TrainJobDuration}} | {{.TrainJobDuration}} | ||||
| </div> | </div> | ||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 规格 | 规格 | ||||
| </td> | </td> | ||||
| @@ -257,7 +260,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 计算节点 | 计算节点 | ||||
| </td> | </td> | ||||
| @@ -274,7 +277,7 @@ td, th { | |||||
| <table class="ti-form"> | <table class="ti-form"> | ||||
| <tbody class="ti-text-form"> | <tbody class="ti-text-form"> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| AI引擎 | AI引擎 | ||||
| </td> | </td> | ||||
| @@ -285,7 +288,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 代码分支 | 代码分支 | ||||
| </td> | </td> | ||||
| @@ -296,7 +299,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 启动文件 | 启动文件 | ||||
| </td> | </td> | ||||
| @@ -307,7 +310,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 训练数据集 | 训练数据集 | ||||
| </td> | </td> | ||||
| @@ -318,7 +321,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 运行参数 | 运行参数 | ||||
| </td> | </td> | ||||
| @@ -329,7 +332,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 训练输出位置 | 训练输出位置 | ||||
| </td> | </td> | ||||
| @@ -340,7 +343,7 @@ td, th { | |||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| <tr class="ti-no-ng-animate"> | <tr class="ti-no-ng-animate"> | ||||
| <td class="ti-no-ng-animate ti-text-form-label"> | |||||
| <td class="ti-no-ng-animate ti-text-form-label text-width80"> | |||||
| 描述 | 描述 | ||||
| </td> | </td> | ||||
| @@ -428,8 +431,34 @@ td, th { | |||||
| e.cancelBubble = true; //ie兼容 | e.cancelBubble = true; //ie兼容 | ||||
| } | } | ||||
| } | } | ||||
| // document.ready(refreshStatus(version_name)) | |||||
| function refreshStatus(version_name){ | function refreshStatus(version_name){ | ||||
| $.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}?version_name=${version_name}`) | |||||
| $.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}?version_name=${version_name}`,(data)=>{ | |||||
| console.log(data) | |||||
| // header status and duration | |||||
| $(`#${version_name}-duration-span`).text(data.JobDuration) | |||||
| $(`#${version_name}-status-span span`).text(data.JobStatus) | |||||
| $(`#${version_name}-status-span i`).attr("class",data.JobStatus) | |||||
| // detail status and duration | |||||
| $('#'+version_name+'-duration').text(data.JobDuration) | |||||
| $('#'+version_name+'-status').text(data.JobStatus) | |||||
| }).fail(function(err) { | |||||
| console.log(err); | |||||
| }); | |||||
| stopBubbling(arguments.callee.caller.arguments[0]) | |||||
| } | |||||
| function deleteVersion(version_name){ | |||||
| $.post(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/del_version`,{version_name:version_name}).fail(function(err) { | |||||
| console.log(err); | |||||
| }); | |||||
| stopBubbling(arguments.callee.caller.arguments[0]) | |||||
| } | |||||
| function stopVersion(version_name){ | |||||
| $.post(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/stop_version`,{version_name:version_name}).fail(function(err) { | |||||
| console.log(err); | |||||
| }); | |||||
| stopBubbling(arguments.callee.caller.arguments[0]) | stopBubbling(arguments.callee.caller.arguments[0]) | ||||
| } | } | ||||
| function loadLog(version_name){ | function loadLog(version_name){ | ||||
| @@ -2785,67 +2785,6 @@ $(document).ready(async () => { | |||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| // dataset Dropzone | |||||
| // const $dataset = $('#dataset'); | |||||
| // if ($dataset.length > 0) { | |||||
| // const filenameDict = {}; | |||||
| // let previewTemplate = ''; | |||||
| // previewTemplate += '<div class="dz-preview dz-file-preview">\n '; | |||||
| // previewTemplate += ' <div class="dz-details">\n '; | |||||
| // previewTemplate += ' <div class="dz-filename">'; | |||||
| // previewTemplate += ' <span data-dz-name data-dz-thumbnail></span>'; | |||||
| // previewTemplate += ' </div>\n '; | |||||
| // previewTemplate += ' <div class="dz-size" data-dz-size></div>\n '; | |||||
| // previewTemplate += ' </div>\n '; | |||||
| // previewTemplate += ' <div class="dz-progress ui active progress">'; | |||||
| // previewTemplate += ' <div class="dz-upload bar" data-dz-uploadprogress><div class="progress"></div></div>\n '; | |||||
| // previewTemplate += ' </div>\n '; | |||||
| // previewTemplate += ' <div class="dz-success-mark">'; | |||||
| // previewTemplate += ' <span>上传成功</span>'; | |||||
| // previewTemplate += ' </div>\n '; | |||||
| // previewTemplate += ' <div class="dz-error-mark">'; | |||||
| // previewTemplate += ' <span>上传失败</span>'; | |||||
| // previewTemplate += ' </div>\n '; | |||||
| // previewTemplate += ' <div class="dz-error-message">'; | |||||
| // previewTemplate += ' <span data-dz-errormessage></span>'; | |||||
| // previewTemplate += ' </div>\n'; | |||||
| // previewTemplate += '</div>'; | |||||
| // await createDropzone('#dataset', { | |||||
| // url: $dataset.data('upload-url'), | |||||
| // headers: {'X-Csrf-Token': csrf}, | |||||
| // maxFiles: $dataset.data('max-file'), | |||||
| // maxFilesize: $dataset.data('max-size'), | |||||
| // acceptedFiles: ($dataset.data('accepts') === '*/*') ? null : $dataset.data('accepts'), | |||||
| // addRemoveLinks: true, | |||||
| // timeout: 0, | |||||
| // dictDefaultMessage: $dataset.data('default-message'), | |||||
| // dictInvalidFileType: $dataset.data('invalid-input-type'), | |||||
| // dictFileTooBig: $dataset.data('file-too-big'), | |||||
| // dictRemoveFile: $dataset.data('remove-file'), | |||||
| // previewTemplate, | |||||
| // init() { | |||||
| // this.on('success', (file, data) => { | |||||
| // filenameDict[file.name] = data.uuid; | |||||
| // const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid); | |||||
| // $('.files').append(input); | |||||
| // }); | |||||
| // this.on('removedfile', (file) => { | |||||
| // if (file.name in filenameDict) { | |||||
| // $(`#${filenameDict[file.name]}`).remove(); | |||||
| // } | |||||
| // if ($dataset.data('remove-url') && $dataset.data('csrf')) { | |||||
| // $.post($dataset.data('remove-url'), { | |||||
| // file: filenameDict[file.name], | |||||
| // _csrf: $dataset.data('csrf') | |||||
| // }); | |||||
| // } | |||||
| // }); | |||||
| // }, | |||||
| // }); | |||||
| // } | |||||
| // Helpers. | // Helpers. | ||||
| $('.delete-button').on('click', showDeletePopup); | $('.delete-button').on('click', showDeletePopup); | ||||
| $('.add-all-button').on('click', showAddAllPopup); | $('.add-all-button').on('click', showAddAllPopup); | ||||
| @@ -3984,243 +3923,6 @@ function initNavbarContentToggle() { | |||||
| }); | }); | ||||
| } | } | ||||
| // function initTopicbar() { | |||||
| // const mgrBtn = $('#manage_topic'); | |||||
| // const editDiv = $('#topic_edit'); | |||||
| // const viewDiv = $('#repo-topics'); | |||||
| // const saveBtn = $('#save_topic'); | |||||
| // const topicDropdown = $('#topic_edit .dropdown'); | |||||
| // const topicForm = $('#topic_edit.ui.form'); | |||||
| // const topicInput = $("#topics_input") | |||||
| // const topicPrompts = getPrompts(); | |||||
| // mgrBtn.on('click', (e) => { | |||||
| // // viewDiv.hide(); | |||||
| // editDiv.css('display', ''); // show Semantic UI Grid | |||||
| // topicInput.val('') | |||||
| // console.log("-----------------asdasd",$("#topics_input"),$("#topics_input").val()) | |||||
| // stopPropagation(e); | |||||
| // }); | |||||
| // $(document).bind('click',function(){ | |||||
| // editDiv.css('display','none'); | |||||
| // }) | |||||
| // editDiv.click(function(e){ | |||||
| // stopPropagation(e); | |||||
| // }) | |||||
| // function getPrompts() { | |||||
| // const hidePrompt = $('div.hide#validate_prompt'); | |||||
| // const prompts = { | |||||
| // countPrompt: hidePrompt.children('#count_prompt').text(), | |||||
| // formatPrompt: hidePrompt.children('#format_prompt').text() | |||||
| // }; | |||||
| // hidePrompt.remove(); | |||||
| // return prompts; | |||||
| // } | |||||
| // function stopPropagation(e) { | |||||
| // var ev = e || window.event; | |||||
| // if (ev.stopPropagation) { | |||||
| // ev.stopPropagation(); | |||||
| // } | |||||
| // else if (window.event) { | |||||
| // window.event.cancelBubble = true;//兼容IE | |||||
| // } | |||||
| // } | |||||
| // saveBtn.on('click', () => { | |||||
| // const topics = $('input[name=topics]').val(); | |||||
| // $.post( | |||||
| // saveBtn.data('link'), | |||||
| // { | |||||
| // _csrf: csrf, | |||||
| // topics | |||||
| // }, | |||||
| // (_data, _textStatus, xhr) => { | |||||
| // if (xhr.responseJSON.status === 'ok') { | |||||
| // console.log("--------saveBtn------------") | |||||
| // viewDiv.children('.topic').remove(); | |||||
| // if (topics.length) { | |||||
| // const topicArray = topics.split(','); | |||||
| // const last = viewDiv.children('a').last(); | |||||
| // for (let i = 0; i < topicArray.length; i++) { | |||||
| // const link = $('<a class="ui repo-topic small label topic"></a>'); | |||||
| // link.attr( | |||||
| // 'href', | |||||
| // `${AppSubUrl}/explore/repos?q=${encodeURIComponent( | |||||
| // topicArray[i] | |||||
| // )}&topic=1` | |||||
| // ); | |||||
| // link.text(topicArray[i]); | |||||
| // link.insertBefore(last); | |||||
| // } | |||||
| // } | |||||
| // editDiv.css('display', 'none'); | |||||
| // viewDiv.show(); | |||||
| // } | |||||
| // } | |||||
| // ) | |||||
| // .fail((xhr) => { | |||||
| // if (xhr.status === 422) { | |||||
| // if (xhr.responseJSON.invalidTopics.length > 0) { | |||||
| // topicPrompts.formatPrompt = xhr.responseJSON.message; | |||||
| // const {invalidTopics} = xhr.responseJSON; | |||||
| // const topicLables = topicDropdown.children('a.ui.label'); | |||||
| // topics.split(',').forEach((value, index) => { | |||||
| // for (let i = 0; i < invalidTopics.length; i++) { | |||||
| // if (invalidTopics[i] === value) { | |||||
| // topicLables | |||||
| // .eq(index) | |||||
| // .removeClass('green') | |||||
| // .addClass('red'); | |||||
| // } | |||||
| // } | |||||
| // }); | |||||
| // } else { | |||||
| // topicPrompts.countPrompt = xhr.responseJSON.message; | |||||
| // } | |||||
| // } | |||||
| // }) | |||||
| // .always(() => { | |||||
| // topicForm.form('validate form'); | |||||
| // }); | |||||
| // }); | |||||
| // topicDropdown.dropdown({ | |||||
| // allowAdditions: true, | |||||
| // forceSelection: false, | |||||
| // fields: {name: 'description', value: 'data-value'}, | |||||
| // saveRemoteData: false, | |||||
| // label: { | |||||
| // transition: 'horizontal flip', | |||||
| // duration: 200, | |||||
| // variation: false, | |||||
| // blue: true, | |||||
| // basic: true | |||||
| // }, | |||||
| // className: { | |||||
| // label: 'ui small label' | |||||
| // }, | |||||
| // apiSettings: { | |||||
| // url: `${AppSubUrl}/api/v1/topics/search?q={query}`, | |||||
| // throttle: 500, | |||||
| // cache: false, | |||||
| // onResponse(res) { | |||||
| // const formattedResponse = { | |||||
| // success: false, | |||||
| // results: [] | |||||
| // }; | |||||
| // const stripTags = function (text) { | |||||
| // return text.replace(/<[^>]*>?/gm, ''); | |||||
| // }; | |||||
| // const query = stripTags(this.urlData.query.trim()); | |||||
| // let found_query = false; | |||||
| // const current_topics = []; | |||||
| // topicDropdown | |||||
| // .find('div.label.visible.topic,a.label.visible') | |||||
| // .each((_, e) => { | |||||
| // current_topics.push(e.dataset.value); | |||||
| // }); | |||||
| // if (res.topics) { | |||||
| // let found = false; | |||||
| // for (let i = 0; i < res.topics.length; i++) { | |||||
| // // skip currently added tags | |||||
| // if (current_topics.includes(res.topics[i].topic_name)) { | |||||
| // continue; | |||||
| // } | |||||
| // if ( | |||||
| // res.topics[i].topic_name.toLowerCase() === query.toLowerCase() | |||||
| // ) { | |||||
| // found_query = true; | |||||
| // } | |||||
| // formattedResponse.results.push({ | |||||
| // description: res.topics[i].topic_name, | |||||
| // 'data-value': res.topics[i].topic_name | |||||
| // }); | |||||
| // found = true; | |||||
| // } | |||||
| // formattedResponse.success = found; | |||||
| // } | |||||
| // if (query.length > 0 && !found_query) { | |||||
| // formattedResponse.success = true; | |||||
| // formattedResponse.results.unshift({ | |||||
| // description: query, | |||||
| // 'data-value': query | |||||
| // }); | |||||
| // } else if (query.length > 0 && found_query) { | |||||
| // formattedResponse.results.sort((a, b) => { | |||||
| // if (a.description.toLowerCase() === query.toLowerCase()) return -1; | |||||
| // if (b.description.toLowerCase() === query.toLowerCase()) return 1; | |||||
| // if (a.description > b.description) return -1; | |||||
| // if (a.description < b.description) return 1; | |||||
| // return 0; | |||||
| // }); | |||||
| // } | |||||
| // return formattedResponse; | |||||
| // } | |||||
| // }, | |||||
| // onLabelCreate(value) { | |||||
| // value = value.toLowerCase().trim(); | |||||
| // this.attr('data-value', value) | |||||
| // .contents() | |||||
| // .first() | |||||
| // .replaceWith(value); | |||||
| // return $(this); | |||||
| // }, | |||||
| // onAdd(addedValue, _addedText, $addedChoice) { | |||||
| // addedValue = addedValue.toLowerCase().trim(); | |||||
| // $($addedChoice).attr('data-value', addedValue); | |||||
| // $($addedChoice).attr('data-text', addedValue); | |||||
| // } | |||||
| // }); | |||||
| // $.fn.form.settings.rules.validateTopic = function (_values, regExp) { | |||||
| // const topics = topicDropdown.children('a.ui.label'); | |||||
| // const status = | |||||
| // topics.length === 0 || (topics.last().attr('data-value').match(regExp) !== null && topics.last().attr('data-value').length <= 35); | |||||
| // if (!status) { | |||||
| // topics | |||||
| // .last() | |||||
| // .removeClass('green') | |||||
| // .addClass('red'); | |||||
| // } | |||||
| // return status && topicDropdown.children('a.ui.label.red').length === 0; | |||||
| // }; | |||||
| // topicForm.form({ | |||||
| // on: 'change', | |||||
| // inline: true, | |||||
| // fields: { | |||||
| // topics: { | |||||
| // identifier: 'topics', | |||||
| // rules: [ | |||||
| // { | |||||
| // type: 'validateTopic', | |||||
| // value: /^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-z0-9-]{0,105}$/, | |||||
| // prompt: topicPrompts.formatPrompt | |||||
| // }, | |||||
| // { | |||||
| // type: 'maxCount[25]', | |||||
| // prompt: topicPrompts.countPrompt | |||||
| // } | |||||
| // ] | |||||
| // } | |||||
| // } | |||||
| // }); | |||||
| // } | |||||
| window.toggleDeadlineForm = function () { | window.toggleDeadlineForm = function () { | ||||
| $('#deadlineForm').fadeToggle(150); | $('#deadlineForm').fadeToggle(150); | ||||