<commit_before>import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
import { IonicPage, ViewController, Platform } from "ionic-angular";
import { OnlineTaskService } from "../../../providers/data.service";
import { VoicePlayService } from "../../../_util/voiceplay.service";
import { GlobalService } from "../../../providers/global.service";
import { VoiceRecorderComponent } from "../../../components/voice-recorder/";
import { baseUrl } from '../../../config'

@IonicPage()
@Component({
	selector: "cmp-task",
	templateUrl: "task.html",
	providers: []
})
export class TaskPage implements OnInit {
	showDismissButton = true;
	page_title = "任务管理";
	taskType = "today";
	openNewTaskForm = false;
	allTasks = {
		finished: new Array(),
		unfinished: new Array()
	};
	newTask = {
		title: "",
		description: "",
		num: 1
	};

	voicepostParams = {}

	voiceUploadUrl ={
		url:baseUrl + "upload/voicefile"
	}

	constructor(
		public taskservice: OnlineTaskService,
		public viewCtrl: ViewController,
		public voiceService: VoicePlayService,
		public globalservice: GlobalService,
		public platform: Platform
	) { }

	@ViewChild(VoiceRecorderComponent)
	voiceRecordCMP: VoiceRecorderComponent;

	ngOnInit() {
		this.taskservice.getTasks().subscribe(
			data => {
				const retStr = data && data._body;
				const dataArr = JSON.parse(retStr);
				this.allTasks.unfinished = dataArr;
				if (dataArr.length > 0 && this.allTasks.unfinished) {
					this.allTasks.unfinished = this.allTasks.unfinished.slice();
				} else {
					this.allTasks.unfinished = [];
					this.allTasks.unfinished = this.allTasks.unfinished.slice();
				}
			},
			err => {
				alert(JSON.stringify(err));
				console.log("getTasks err", err);
			}
		);
	}

	playVoiceRecord(task) {
		if(task.voiceUrl){
			let filename = this.getFileName(task.voiceUrl);
			// filename格式示例:pengyi_59ae098c49b3972f7176003b_cordovaIMVoice
			this.voiceService.downloadVoiceFile(filename,this.globalservice.token);
		}else{
			alert("此任务无音频记录！")
		}
	}

	getFileName(url) {
		let arr = url.split('/');
		let fileName = arr[arr.length - 1];
		return fileName;
	}

	addNewTaskLink() {
		this.openNewTaskForm = true;
		this.page_title = '添加新任务';
		this.showDismissButton = false
		this.voicepostParams = {
			userid: 'userid',
			taskid: 'taskid'
		}
	}

	addTask = function (isActive: any) {
		let task = this.newTask;
		// task.num = 1;
		task.isActive = isActive;
		task.voiceUrl = "";<commit_msg>set new added task default state to active<commit_after>import { Component, OnInit, ElementRef, ViewChild } from "@angular/core";
import { IonicPage, ViewController, Platform } from "ionic-angular";
import { OnlineTaskService } from "../../../providers/data.service";
import { VoicePlayService } from "../../../_util/voiceplay.service";
import { GlobalService } from "../../../providers/global.service";
import { VoiceRecorderComponent } from "../../../components/voice-recorder/";
import { baseUrl } from '../../../config'

@IonicPage()
@Component({
	selector: "cmp-task",
	templateUrl: "task.html",
	providers: []
})
export class TaskPage implements OnInit {
	showDismissButton = true;
	page_title = "任务管理";
	taskType = "today";
	openNewTaskForm = false;
	allTasks = {
		finished: new Array(),
		unfinished: new Array()
	};
	newTask = {
		title: "",
		description: "",
		num: 1
	};

	voicepostParams = {}

	voiceUploadUrl ={
		url:baseUrl + "upload/voicefile"
	}

	constructor(
		public taskservice: OnlineTaskService,
		public viewCtrl: ViewController,
		public voiceService: VoicePlayService,
		public globalservice: GlobalService,
		public platform: Platform
	) { }

	@ViewChild(VoiceRecorderComponent)
	voiceRecordCMP: VoiceRecorderComponent;

	ngOnInit() {
		this.taskservice.getTasks().subscribe(
			data => {
				const retStr = data && data._body;
				const dataArr = JSON.parse(retStr);
				this.allTasks.unfinished = dataArr;
				if (dataArr.length > 0 && this.allTasks.unfinished) {
					this.allTasks.unfinished = this.allTasks.unfinished.slice();
				} else {
					this.allTasks.unfinished = [];
					this.allTasks.unfinished = this.allTasks.unfinished.slice();
				}
			},
			err => {
				alert(JSON.stringify(err));
				console.log("getTasks err", err);
			}
		);
	}

	playVoiceRecord(task) {
		if(task.voiceUrl){
			let filename = this.getFileName(task.voiceUrl);
			// filename格式示例:pengyi_59ae098c49b3972f7176003b_cordovaIMVoice
			this.voiceService.downloadVoiceFile(filename,this.globalservice.token);
		}else{
			alert("此任务无音频记录！")
		}
	}

	getFileName(url) {
		let arr = url.split('/');
		let fileName = arr[arr.length - 1];
		return fileName;
	}

	addNewTaskLink() {
		this.openNewTaskForm = true;
		this.page_title = '添加新任务';
		this.showDismissButton = false
		this.voicepostParams = {
			userid: 'userid',
			taskid: 'taskid'
		}
	}

	addTask = function (isActive: any) {
		let task = this.newTask;
		// task.num = 1;
		task.isActive = true;
		task.voiceUrl = "";
{'fraction_non_alphanumeric': 0.14865683700262572, 'fraction_numerical': 0.00888709351646132, 'mean_word_length': 3.734225621414914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6860413', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1674, 'n_words': 323}