function projectCtrl($scope,Project) {
    $scope.item = "adsfasdfsadf";
    function project(){
        this.name = "";
        this.is_default = 0;
        this.urls = [];
    }
    $scope.new_project = new project();
    $scope.projects = [];
    $scope.saveProject = function(){
        Project.save($scope.new_project,function(res){
            console.log(res)
            if(res.code){
                toastr.error(`保存错误：${res.code}`)
                return
            }
            toastr.success("项目保存成功")
            $scope.projects.push(res)
        },function(res){
            toastr.error(`程序错误:${res}`)
        })
    }

    $scope.getProjects = function(){
        Project.query({},function(res){
            $scope.projects = res;
        })
    }

    $scope.editProjectUrls = function(pro){
        $scope.$emit("setCurrentProject",pro);
        $scope.showTab("url");
    }
    $scope.deleteProject = function(project){
        Project.delete({
            _id: project._id
        },function(res){
            if(res.code == "0000"){
                _.remove($scope.projects,{_id:project._id});
                toastr.success("删除成功")
            }else{
                toastr.error(`删除错误：${res.code}`)
            }
            
        })
    }
    $scope.getProjects()
}   
projectCtrl.$inject = ["$scope","Project"];
BP.controller("projectCtrl", projectCtrl);
