/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.settingsList;

import jetbrains.buildServer.BuildTypeDescriptor;
import jetbrains.buildServer.serverSide.ProjectManager;
import jetbrains.buildServer.web.openapi.*;
import org.jetbrains.annotations.NotNull;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Example custom page controller
 */
public class SettingsListTab extends SimpleCustomTab {
    private ProjectManager myProjectManager;

    public SettingsListTab(PluginDescriptor pluginDescriptor, WebControllerManager manager, ProjectManager projectManager, PagePlaces pagePlaces) {
        super(pagePlaces,
                PlaceId.ADMIN_SERVER_CONFIGURATION_TAB,
                "settingsList",
                pluginDescriptor.getPluginResourcesPath("settingsList.jsp"),
                "VCS Settings List");
        setPosition(PositionConstraint.last());
        myProjectManager = projectManager;
    }

    @Override
    public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
        model.put("buildTypes", myProjectManager.getAllBuildTypes());

        Map<BuildTypeDescriptor.CheckoutType, String[]> checkoutTypeMapper = new HashMap<BuildTypeDescriptor.CheckoutType, String[]>(3);
        checkoutTypeMapper.put(BuildTypeDescriptor.CheckoutType.ON_SERVER, new String[]{"on server", "left"});
        checkoutTypeMapper.put(BuildTypeDescriptor.CheckoutType.ON_AGENT, new String[]{"on agent", "right"});
        checkoutTypeMapper.put(BuildTypeDescriptor.CheckoutType.MANUAL, new String[]{"no checkout", "center"});
        model.put("checkoutTypeMapper", checkoutTypeMapper);
    }
}
