<commit_before>import Component from '@ember/component';
import { empty } from '@ember/object/computed';

export default Component.extend({
    type: '',
    value: '',
    isEditing: false,
    user: null,
    disableSave: empty('user.email'),
    notValidEmail: false,
    prevEmail: '',
    emailIsNull: true,

    actions: {
        editEmail() {
            let user = this.get('user');
            let isEmailNull = function(user) {
                if (user.email == null) {
                    return true;
                } else {
                    return false;
                }
            };

            this.set('emailIsNull', isEmailNull(user));
            this.set('isEditing', true);
            this.set('prevEmail', this.get('value'));
        },

        saveEmail() {
            let userEmail = this.get('value');
            let user = this.get('user');

            let emailIsProperFormat = function(userEmail) {
                let regExp = /\S+@\S+\.\S+/;
                return regExp.test(userEmail);
            };

            if (!emailIsProperFormat(userEmail)) {
                this.set('notValidEmail', true);
                return;
            }

            user.set('email', userEmail);
            user.save()
                .then(() => this.set('serverError', null))
                .catch(err => {
                    let msg;
                    if (err.errors && err.errors[0] && err.errors[0].detail) {
                        msg = `An error occurred while saving this email, ${err.errors[0].detail}`;
                    } else {<commit_msg>display 'please add email' message only when email is not already added<commit_after>import Component from '@ember/component';
import { empty } from '@ember/object/computed';

export default Component.extend({
    type: '',
    value: '',
    isEditing: false,
    user: null,
    disableSave: empty('user.email'),
    notValidEmail: false,
    prevEmail: '',
    emailIsNull: true,

    actions: {
        editEmail() {
            let email = this.get('value');
            let isEmailNull = function(email) {
                if (email == null) {
                    return true;
                } else {
                    return false;
                }
            };

            this.set('emailIsNull', isEmailNull(email));
            this.set('isEditing', true);
            this.set('prevEmail', this.get('value'));
        },

        saveEmail() {
            let userEmail = this.get('value');
            let user = this.get('user');

            let emailIsProperFormat = function(userEmail) {
                let regExp = /\S+@\S+\.\S+/;
                return regExp.test(userEmail);
            };

            if (!emailIsProperFormat(userEmail)) {
                this.set('notValidEmail', true);
                return;
            }

            user.set('email', userEmail);
            user.save()
                .then(() => this.set('serverError', null))
                .catch(err => {
                    let msg;
                    if (err.errors && err.errors[0] && err.errors[0].detail) {
                        msg = `An error occurred while saving this email, ${err.errors[0].detail}`;
                    } else {
{'fraction_non_alphanumeric': 0.1347517730496454, 'fraction_numerical': 0.0018501387604070306, 'mean_word_length': 1.4409330323551544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '749516', 'n_tokens_mistral': 879, 'n_tokens_neox': 837, 'n_words': 189}